Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htmlAttributes MVC 5.1 Editor for

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?

like image 894
user3361393 Avatar asked Feb 27 '14 16:02

user3361393


1 Answers

You can get them from the ViewData:

@{
    var htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(ViewData["htmlAttributes"]);
    htmlAttributes.Add("key", "value"); //add new value
}
like image 62
Zabavsky Avatar answered Oct 18 '22 16:10

Zabavsky