Skip to content

HtmlHelperExtensions should use TemplateInfo to generate element names #30

@benfoster

Description

@benfoster

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions