---
title: "Post data from view to controller using ajax"  
description: "Post data from view to controller using ajax"  
author: "Ailsa Singh"  
published: 2017-06-22  
updated: 2017-06-22  
canonical: https://www.mindstick.com/forum/34314/post-data-from-view-to-controller-using-ajax  
category: "ajax"  
tags: ["asp.net", "ajax", "mvc"]  
reading_time: 1 minute  

---

# Post data from view to controller using ajax

I want to [post](https://www.mindstick.com/articles/12829/aspects-that-make-australia-post-shipping-extension-a-useful-tool) [data from view](https://www.mindstick.com/forum/12778/how-to-send-data-from-view-to-controller-action-in-asp-dot-net-mvc) to [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) using ajax.

I am novice in Ajax. Please help me.

This is my View code.

```
  @using (Html.BeginForm("SignIn","Home",FormMethod.Post))       
{          
<fieldset>   
<legend>Login:</legend>   
User Name: @Html.TextBoxFor(x=>x.UserName)<br>   
Password: @Html.PasswordFor(x=>x.Password)<br> <input type="submit" value="Login" />@ViewBag.error                      }                </div>
```

## Replies

### Reply by Sushant Mishra

You have to use following js library for ajax

```
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script><script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script><script src="~/Scripts/jquery.validate.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.2/jquery.validate.unobtrusive.js"></script> @using(Ajax.BeginForm("index","Home", new AjaxOptions{   
HttpMethod = "POST",//method post   
UpdateTargetId = "target",//   
OnSuccess = "updateSuccess"//})){     
<center><h2>Registration Form</h2></center>   
@Html.ValidationSummary(true)     
<hr />   
<div>       
<center> <table border="0"  width="70%" cellspadding="0" cellspacing="0">       
<tr>             <td><label id="label1">User Name</label>                @Html.HiddenFor(x => x.Id, new { @Value = 0 })            </td>              <td>@Html.TextBoxFor(x =>x.UserName)                  @Html.ValidationMessageFor(m=> m.UserName)              </td>            <td><label id="label2">Father Name</label></td>              <td>@Html.TextBoxFor(x =>x.FName)                  @Html.ValidationMessageFor(m=> m.FName)              </td>       
</tr>      
<tr>            <td><label id="label3">Email</label></td>              <td>@Html.TextBoxFor(x =>x.Email)                  @Html.ValidationMessageFor(m=> m.Email)              </td>            <td><label id="label4">Mobile</label></td>              <td>@Html.TextBoxFor(x =>x.Mobile)                  @Html.ValidationMessageFor(m=> m.Mobile)              </td>       
</tr>      
<tr>        
<td colspan="2"> <br /> <center>               <input type="submit" value="Submit" /></center>          
</td>      
</tr>   
</table></center>   
</div>      
   
 } <div
id="target">   
@Html.Partial("UserList");</div><script>   
function updateSuccess(data) {       
$('form')[0].reset();   
}</script>
```

hope this helps you..\

\

\


---

Original Source: https://www.mindstick.com/forum/34314/post-data-from-view-to-controller-using-ajax

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
