Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HtmlHelperExtensions should use TemplateInfo to generate element names #30

Open
benfoster opened this issue Feb 4, 2014 · 1 comment
Labels

Comments

@benfoster
Copy link
Owner

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);
@JenTechSystems
Copy link

Thanks for providing the solution for this Ben!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants