Fabrik.Common icon indicating copy to clipboard operation
Fabrik.Common copied to clipboard

HtmlHelperExtensions should use TemplateInfo to generate element names

Open benfoster opened this issue 11 years ago • 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);

benfoster avatar Feb 04 '14 09:02 benfoster

Thanks for providing the solution for this Ben!

JenTechSystems avatar Feb 04 '14 13:02 JenTechSystems