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
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);
}