c# - Change mvc form validation error messages -


i trying change data-val-required attributes of form fields generic "required" appear. know can using following:

@html.textboxfor(model => model.name, new { data_val_required ="required" }) 

but don't want "hard code" template that, prefer model use required attribute set on , override through js using this:

$('input, select, textarea').each(function () {     var element = $(this);     if (element.data('val-required')) {         element.data('val-required', 'required');     } }); 

i've run on document ready , checked data attributes have changed (which have) apparently happening late validation take note of it. need know when mvc binds it's form validation can run before or how change error messages clientside only.

i've looked through source of page , can't see validate gets instantiated.

for saying change required attribute or server side, don't want if have js disabled display validation summary @ top of form pretty useless if required. why want client side only

enter image description here

for of interested in solution, following reset validation messages:

(function () {     $('input, select, textarea').each(function () {         var element = $(this);         if (element.data('val-required')) {             element.attr('data-val-required', 'required'); // please note has attr not data         }     });      form = $('form');     form.removedata("validator").removedata("unobtrusivevalidation");     $.validator.unobtrusive.parse(form); }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -