Làm cách nào để hiển thị lỗi ModelState được trả về bởi JSON?Làm thế nào để đọc lỗi mô hình khi được trả về bởi Json?
tôi muốn làm một cái gì đó như thế này:
if (!ValidateLogOn(Name, currentPassword))
{
ModelState.AddModelError("_FORM", "Username or password is incorrect.");
//Return a json object to the javascript
return Json(new { ModelState });
}
gì phải mã của tôi trong giao diện để đọc các lỗi ModelState và hiển thị chúng?
mã thực tế của tôi trong giao diện để đọc các giá trị JSON là như sau:
function createCategoryComplete(e) {
var obj = e.get_object();
alert(obj.Values);
}
Có một giải pháp ở đây: http://stackoverflow.com/questions/2845852/asp-net-mvc-how-to-convert-modelstate-errors-to-json –