MVC求助 ~~~~~急!!!
问题如下:
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);
[解决办法]
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()); }