I have set up model validation for my form but validation doesn\'t seem to work at all. I don\'t suppose anybody can help. I\'ve tried using the below work-around but that k
Its too late to change the ignore on the validator in this way after the unobtrusive script. This is because the validator only pulls in the defaults once - when it is created. The unobtrusive script creates the validator for you. You need to reference the existing validator object and update it.
try this
<script>
$(document).ready(function () {
$('form').validate().settings.ignore = []
});
</script>
If you don't have to use javascript, in your Controller, and in your action of the related view, you can add a model error before validating your model. Example:
[HttpPost]
public ActionResult Fix(YourModel mdl)
{
if (mdl.Customer_ID>Int32.MaxValue || mdl.Customer_ID<1)
ModelState.AddModelError("", "Your error message!");
if (ModelState.IsValid)
{
//
//Some code
//
return View("YourView", yourlist);
}
return View(mdl);
}