标签:style blog color io for 数据 div sp log
模板方法包括Display/DisplayFor、Editor/EditorFor、DisplayForModel/EditForModel提供辅助生成Html的模型元数据信息
1 public static MvcHtmlString EditorForModel(this HtmlHelper html, string templateName, string htmlFieldName, object additionalViewData) 2 { 3 return MvcHtmlString.Create(TemplateHelpers.TemplateHelper(html, html.ViewData.ModelMetadata, htmlFieldName, templateName, DataBoundControlMode.Edit, additionalViewData)); 4 }
获取模型元数据
1 public virtual ModelMetadata ModelMetadata
2 {
3 get
4 {
5 if (this._modelMetadata == null && this._model != null)
6 {
7 this._modelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => this._model, this._model.GetType());
8 }
9 return this._modelMetadata;
10 }
11 set
12 {
13 this._modelMetadata = value;
14 }
15 }
asp.net MVC 4.0 Model元数据回顾——HtmlHelper的ModelMetadata
标签:style blog color io for 数据 div sp log
原文地址:http://www.cnblogs.com/raohuagang/p/3984553.html