读书人

MVC ~

发布时间: 2012-08-30 09:55:54 作者: rapoo

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);
[解决办法]

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());                } 

读书人网 >asp.net

热点推荐