I know that this is a very common question but I can't find any one that solve my problem.
I am using Asp.net mvc5. I am making an Ajax call using the helpers that provide asp. The code in the template looks like this.
@using (Ajax.BeginForm("Register", "Account",null , new AjaxOptions
{
HttpMethod = "POST",
Url = "/Account/Register/",
OnSuccess = "onSuccess"
}))
{
<p>@Html.ValidationMessage("Register.Email")</p>
@Html.TextBox("Email", null, new { placeholder = "Enter your email")
<input type="submit" value="submit" />
}
My problem here is that I want to show the validations errors that come from the server using the ajax callback, without re-rendering the page.
Now my question is. How must I write the action on the controller to handle this problem automatically? By automatically I mean what is the way to return something on the controller action that populates the error fields when the model is not valid.
Any help will be appreciated, thanks.