问题如下:var  htmlattr=new {@class="a",style=""}请问怎么将上述代码存进Dictionary中

解决方案 »

  1.   

    var dic=new Dictionary<string,object>();
    dic.Add('htmlattr',new{@class="a",style=""});
    ?
      

  2.   

    MVC中HtmlHelper内置方法
    IDictionary<string, object> attrs = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
      

  3.   

      var htmlattr = new { @class = "a", style = "" };
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    foreach (System.Reflection.PropertyInfo p in htmlattr.GetType().GetProperties())
                    {
                        dic.Add(p.Name, p.GetValue(htmlattr,null).ToString());
                    }