问题如下:
var htmlattr=new {@class="a",style=""}
请问怎么将上述代码存进Dictionary中
------解决方案--------------------------------------------------------
var dic=new Dictionary<string,object>();
dic.Add('htmlattr',new{@class="a",style=""});
?
------解决方案--------------------------------------------------------
MVC中HtmlHelper内置方法
IDictionary<string, object> attrs = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
------解决方案--------------------------------------------------------
- C# code
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()); }