I want to add the "data-val-required" and "data-val" attributes to an @html.textbox or an @Html.EditorFor element. Is it possible without rewriting the view?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
Normally you should not rewrite the view to achieve that. You should decorate your view model properties with the corresponding validation attributes. For example:
Then the Html helpers will generate the correct markup. But if for some weird reason you cannot modify this code you could use javascript in order to add those attributes manually:
Once you add those attributes you need to reparse the validation rules of the form containing those input fields for your changes to take effect: