I have added the following line to my view
@Html.EditorFor(model => model, new { htmlAttributes = new { @class = "form-control" }, })
How do I access the htmlAttributes in the corresponding EditorTemplate Razor view?
Also how do I add some values to the existing passed in htmlAttributes in the EditorTemplate View?
You can get them from the ViewData
:
@{
var htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(ViewData["htmlAttributes"]);
htmlAttributes.Add("key", "value"); //add new value
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With