Marcin M
Marcin M

Reputation: 375

Prevent MVC 4 to add "type" and "data-val-" attribut on html tags

How to force MVC4 to stop adding 'type="" ' and 'data-val-...' attributes?

Eg. <input type="number" data-val-number="The field Months must be a number." />

Upvotes: 2

Views: 1466

Answers (1)

krilovich
krilovich

Reputation: 3505

Those are added automatically by the HTML helpers you are using.

You have three options:

1) Create your own HTML helper that doesn't add data-val

http://www.asp.net/mvc/tutorials/hands-on-labs/aspnet-mvc-4-helpers,-forms-and-validation#Exercise2

2) user jQuery to remove data-val attributes from the inputs you want

http://api.jquery.com/removeAttr/

3) Simply don't use HTML helpers and create the input tag yourself

Upvotes: 1

Related Questions