当前位置: 代码迷 >> ASP.NET >> MVC ~
  详细解决方案

MVC ~

热度:7276   发布时间:2013-02-25 00:00:00.0
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());                }
  相关解决方案