benfoster/Fabrik.Common

HtmlHelperExtensions should use TemplateInfo to generate element names

Opened this issue · 1 comments

Helpers such as Html.CheckBoxListFor currently use ExpressionHelper.GetExpressionText(expression) to generate element names. This generates an incorrect name when using the helper within nested editor templates. E.g.

Index.cshtml:

@Html.EditorFor(model => model.Other)

EditorTemplates/Other.cshtml

@Html.CheckBoxListFor(model => model.Tags, Model.AvailableTags)

Should generate the field name Other.Tags but is actually just Tags.

The solution is to use TemplateInfo to get the full name:

var name = ExpressionHelper.GetExpressionText(expression);
var fullName = helper.ViewData.TemplateInfo.GetFullHtmlFieldName(name);

Thanks for providing the solution for this Ben!