I am using telerik mvc grid. In my table I have unique key defined for a field. And in controller I am catching the error using try ... catch inside DbUpdateException.
in catch block I want to handle the error and show error messsage in view. So using following line,
ModelState.AddModelError("PROGRAM_ID", "Access for this program already exists.");
return View();
But this is not showing error message. Any idea why?
Make sure that you have a corresponding ValidationMessage
in your view with the same key:
@Html.ValidationMessage("PROGRAM_ID")