In my opinion, I call Html.EditFor (), which runs my own template template for this data type. In addition, I pass him some metadata (and what I don't like):
<% ModelMetadata metaTitle = ModelMetadataProviders.Current.GetMetadataForProperty(null, Model.GetType(), "Title"); %> <%: Html.EditorFor(x => Model.Title, new { metaData = metaTitle })%>
The missing type (property name) is of type "Translation". Within a custom editor template, I need to read the passed metadata from viewData in order to use it:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Translation>" %> // {...} if (ViewData["metaData"] != null) metaData = (ModelMetadata)ViewData["metaData"];
Is there a way to access metadata directly in a custom editor template? Unfortunately, if I call the following in the editor template, I will not get the same metadata object (where, for example, there is no information if the Title-Property is required or not):
ModelMetadata metaData = ModelMetadataProviders.Current.GetMetadataForType(null, Model.GetType());
I would like to avoid passing the metadata object on every call ...
thanks for any tips! sl3dg3
source share