---
title: "How do you handle model validation errors in an AJAX form submission without reloading the page?"  
description: "How do you handle model validation errors in an AJAX form submission without reloading the page?"  
author: "Anubhav Sharma"  
published: 2025-07-28  
updated: 2025-08-05  
canonical: https://www.mindstick.com/forum/161834/how-do-you-handle-model-validation-errors-in-an-ajax-form-submission-without-reloading-the-page  
category: "asp.net mvc"  
tags: ["mvc", "ajaxform"]  
reading_time: 1 minute  

---

# How do you handle model validation errors in an AJAX form submission without reloading the page?

**How do you [handle model](https://www.mindstick.com/forum/159706/how-to-handle-model-validation-errors-in-a-dot-net-core-api) [validation errors](https://www.mindstick.com/forum/160109/how-to-handle-exceptions-caused-by-data-validation-errors-in-api-input-parameters) in an [AJAX form](https://www.mindstick.com/interview/34343/explain-how-client-side-events-like-onsuccess-onfailure-and-onbegin-work-in-an-ajax-form) [submission](https://www.mindstick.com/forum/156176/what-is-a-directory-submission) without reloading the [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page)?**

- How would you show `ModelState` errors dynamically on the page?

## Replies

### Reply by ICSM Computer

Handling [model validation](https://www.mindstick.com/blog/646/model-validation-in-asp-dot-net-mvc-4) [errors](https://answers.mindstick.com/qa/116170/fresh-fir-against-gandhis-in-national-herald-case-cover-up-for-ed-s-own-errors) in an AJAX form in ASP.NET MVC:

### 1. View (Main Form)

Use `Ajax.BeginForm` with `UpdateTargetId`:

```plaintext
<div id="formContainer">
    @Html.Partial("_FormPartial", Model)
</div>
```

### 2. Partial View: _FormPartial.cshtml

```plaintext
@model MyViewModel
@using (Ajax.BeginForm("SubmitForm", "Home", new AjaxOptions {
    UpdateTargetId = "formContainer", InsertionMode = InsertionMode.Replace, HttpMethod = "POST"
}))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    @Html.TextBoxFor(m => m.Name)
    @Html.ValidationMessageFor(m => m.Name)
    <input type="submit" value="Submit" />
}
```

### 3. Controller

```plaintext
[HttpPost]
public ActionResult SubmitForm(MyViewModel model)
{
    if (!ModelState.IsValid)
        return PartialView("_FormPartial", model); // return form with errors

    return PartialView("_SuccessPartial", model);  // return success view
}
```

### 4. Scripts

Make sure these are included:

```html
<script src="jquery.js"></script>
<script src="jquery.validate.js"></script>
<script src="jquery.validate.unobtrusive.js"></script>
<script src="jquery.unobtrusive-ajax.js"></script>
```

### 5. Re-enable Validation After AJAX

```javascript
$(document).ajaxComplete(function () {
    $.validator.unobtrusive.parse("#formContainer");
});
```


---

Original Source: https://www.mindstick.com/forum/161834/how-do-you-handle-model-validation-errors-in-an-ajax-form-submission-without-reloading-the-page

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
