This project is read-only.

use of htmlField name in EditorTemplate

Dec 5, 2013 at 10:42 AM
I would like to create a custom editor template for select a month, creating a dropdownlist with the months, and call from the view using the helper

MvcHtmlString Editor(this HtmlHelper html, string expression, string templateName, string htmlFieldName);

passing the template name and the htmlfieldname.

How can I use the fieldName from inside the template itself?

Dec 6, 2013 at 6:07 PM
That value is available in an custom editor template as part of @ViewData.TemplateInfo.HtmlFieldPrefix or equivalently @Html.NameForModel(). More specifically the htmlFieldName parameter forms the last segment of the editor's field prefix e.g. "Previous.Prefix.htmlFieldName", with special cases for a previously-empty prefix and a square bracket starting the field name (indicating it’s an indexer). The field prefix affects view data lookups in addition to generated names.

I'm curious why you chose that particular @Html.Editor() overload?