Showing posts with label ASP.NET MVC. Show all posts

ASP MVC unobtrusive validation for dynamic html

When I add the dynamic content to page with javascript or ajax, the validation doesn't work with new content at all. I solved the problem by 2 ways.

Solution 1: Parse only changed content
$("#yourID").html(yourContent); // add html to your tag
$.validator.unobtrusive.parse($("#yourID")); // this will parse validation for new content
Solution 2: Parse validation for form tag
$.removeData($('#YourFormID').get(0), 'validator'); // clear the validation of the form tag
jQuery.validator.unobtrusive.parse('#YourFormID');

Posted in | Leave a comment

Change default error message "The value ... is not valid for..."

This is my solution. Tested on MVC 3 and MVC 4.

  1. Create App_GlobalResources folder in project (easy way is right click to project -> Add -> Add ASP.NET folder -> App_GlobalResource).
  2. Add a resx file to App_GlobalResources (e.g. YourResource.resx).
  3. Add resource key "PropertyValueInvalid". By default, the message is "The value {0} is not valid for {1}". You can change or translate whatever you want.
  4. Add the code DefaultModelBinder.ResourceClassKey = "YourResource" to Application_Start function in Global.asax.

Posted in | Leave a comment

Search

Swedish Greys - a WordPress theme from Nordic Themepark. Converted by LiteThemes.com.