I have the following action method:-
public ActionResult AddServerToRack(AddServerToRack s)
{
if (ModelState.IsValid)
{
try
{
// code goes here
}
}
var errorDesc = ModelState.Select(a=>a.Value.Errors.Select(a2=>a2.ErrorMessage)).ToList();
string desc = "";
foreach (var i in errorDesc)
{
desc = desc + " " + i.ToString();
}
return Json(new { IsSuccess = false, description = desc}, JsonRequestBehavior.AllowGet);
}
what i am trying to do is to get all the error messages inside the model state and send them as a json object. but currently i fail to get the description of the error message using the foreach at the end of my action method. so can anyone advice , how i can get all the modelstates error message description .? Thanks