Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding multiple class tags to MVC HTML helper

I need to assign multiple classes to an MVC TextBox HTML helper, so it functions the same as when assigning multiple classes to an HTML element.

i.e.: <div class="class1, class2"></div>

The following does not work properly:

@Html.TextBoxFor(x => x.Name, new { @class = "class1, class2" })

Note: I need to add both class names to a single element in order to trigger different jQuery functions. Any advice would be greatly appreciated.

like image 329
gemini6609 Avatar asked Jul 15 '14 20:07

gemini6609


1 Answers

Close:

@Html.TextBoxFor(x => x.Name, new { @class = "class1 class2" })

...produces the following HTML:

<input class="class1 class2" data-val="true" data-val-required="Name is required" id="Name" name="Name" type="text" value="">
like image 57
m.casey Avatar answered Oct 20 '22 15:10

m.casey