Post data from view to controller using ajax

Total Post:22


ASP.Net  AJAX  Mvc 
 1302  View(s)
Rate this:

I want to post data from view to controller using ajax.

I am novice in Ajax. Please help me.

This is my View code.

  @using (Html.BeginForm("SignIn","Home",FormMethod.Post))
    User Name: @Html.TextBoxFor(x=>x.UserName)<br>
    Password: @Html.PasswordFor(x=>x.Password)<br>
 <input type="submit" value="Login" />@ViewBag.error 

  1. Re: Post data from view to controller using ajax

    You have to use following js library for ajax 

    <script src=""></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src=""></script>
    @using(Ajax.BeginForm("index","Home", new AjaxOptions
        HttpMethod = "POST",//method post
        UpdateTargetId = "target",//
        OnSuccess = "updateSuccess"//
        <center><h2>Registration Form</h2></center>
        <hr />
            <center> <table border="0"  width="70%" cellspadding="0" cellspacing="0">
                 <td><label id="label1">User Name</label>
                    @Html.HiddenFor(x => x.Id, new { @Value = 0 })
                  <td>@Html.TextBoxFor(x =>x.UserName)
                      @Html.ValidationMessageFor(m=> m.UserName)
                <td><label id="label2">Father Name</label></td>
                  <td>@Html.TextBoxFor(x =>x.FName)
                      @Html.ValidationMessageFor(m=> m.FName)
                <td><label id="label3">Email</label></td>
                  <td>@Html.TextBoxFor(x =>x.Email)
                      @Html.ValidationMessageFor(m=> m.Email)
                <td><label id="label4">Mobile</label></td>
                  <td>@Html.TextBoxFor(x =>x.Mobile)
                      @Html.ValidationMessageFor(m=> m.Mobile)
             <td colspan="2"> <br /> <center>
                   <input type="submit" value="Submit" /></center>
    <div id="target">
        function updateSuccess(data) {

    hope this helps you..

      Modified On Apr-11-2018 11:02:02 PM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.