模板方法包括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 }
时间: 2024-10-13 10:16:02