This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
Most string-based HTML helpers use unprefixed ViewDataDictionary
entries if called from templates #1487
Closed
Description
The string-based helpers not mentioned in #1485 (@Html.TextArea()
etc.) also do not behave as expected in template views. But this problem occurs only if an entry exists in the ViewDataDictionary
matching the (un-prefixed) expression name. So unexpected values will be used in the generated HTML -- luckily, in a somewhat narrow case.
E.g. action contains
ViewData["Age"] = 39;
return View(new User()
{
Age = 26,
Dependent = new User()
{
Age = 13,
},
});
Index.cshtml contains
@Html.DisplayFor(model => model.Dependent, templateName: "Dependent")
DisplayTemplates/Dependent.cshtml contains:
<td>
@Html.Label(expression: "Age", labelText: null, htmlAttributes: new { @class = "control-label", })
</td>
<td>
'@Html.Value(name: "Age")'
</td>
Expect to see "13" displayed between the quotes.