I am using MVC3 + Razor. Now I have a form which contains Ajax.BeginForm(...). I following exact what "Maxim" said in this post:
ASP.NET MVC AJAX with HTML.ValidationMessageFor
And my validation rule is defined like:
ModelState.AddModelError("ControlName", "error message");
However my
@Html.ValidationMessageFor(model => Model.OneProperty[0].AnotherProperty)
didn't give me anything.
I also put these code into partial-view for "error summary" as well. I could see code run through the "ValidationSummary" PV, but it just doesn't display.
if (!ViewData.ModelState.IsValid)
{
<div id="errorMessage" class="notificationArea">
@Html.Partial("ValidationSummary")
</div>
}
In short, my main view is this:
@using (Ajax.BeginForm("SaveFromMainView", null, new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "myForm"
},
new { id = "myForm" }))
{
@Html.Partial("SamTest1")
}
And within this "SamTest1" partial-view, there is another "ValidationSummary" partial-view to display bullets of error message.
And my action method fianlly:
return PartialView("SamTest1");
Thanks heaps in advance!