10

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.

1 Answer 1

19

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="">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.