Here are the codes
public class MyModel
{
[Required]
public string Title {get;set;}
}
public class MyController : Controller
{
public ActionResult Post(MyModel model)
{
if (!ModelState.IsValid)
return PartialView(model);
return PartialView("SomeOtherView");
}
}
Here is my View
@model MyModel
@using(Ajax.BeginForm("Post","My",new AjaxOptions{OnSuccess = "Sucess" }) {
Html.Partial("Post",Model)
}
<script>
function Success(content)
{
$("#somediv").html(content);
}
</script>
Now, when ModelState Dictionary has no error, everything goes well, but when there is some model validation error, I have no way to detect it in javascript. Can someone help here.
Regards
Parminder
There are different ways to achieve this. One way is to have the server side send a proper HTTP code (500) in case of error:
and on the client subscribe for the
OnFailurecallback and handle the error case in a different function.