Introduction
- How to add jquery in project
- Where NuGet stores installed Packages details
- Jquery Ajax Form Submit using Serializing Form Data into a Model

Create a project called “AspNetMvcJqueryAjaxSerializeForm”
Click Ok to proceed
By default view after “AspNetMvcJqueryAjaxSerializeForm”project created.
In empty project template visual studio will not give any controller , model and view. All three folders called CONTROLLERS, MODELS and VIEWS are blank only Web.Config file exists inside VIEWS folder.
Now we are going to add Jquery into project with help of NUGET.
Right Click on Project title inside SOLULTION EXPLORER.
How to add jquery in project?
Select option called Manage NuGet Packages. . .
Follow the simple steps as given in image
STEPS
- Select browse to do search for jquery.
- Type “Jquery” to search.
- Single click on Jquery
- You can select your desired version.
- Click on Install
In the above you can see jquery installed successfully. You can even see Package.config file.
Where NuGet store installed Packages details?


- Index.
- Details
- Create -- HTTP GET
- Create - HTTP POST
- Edit -- HTTP GET
- Edit - HTTP POST
- Delete - HTTP GET
- Delete - HTTP POST
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace AspNetMvcJqueryAjaxSerializeForm.Models
- {
- public class FriendModel
- {
- public string FriendName { get; set; }
- public string Phone { get; set; }
- public string State { get; set; }
- }
- }
At left side bottom you can see “Build Succeeded”.
Right click on Create ActionResult.
Now you can see in Shared folder ---> _Layout.cshtml created.
- <script src="~/Scripts/jquery-1.10.2.min.js"></script>

Copy this link and paste at head section, we had added latest version of jquery and you can cross check in SCRIPTS folder the jquery version. Change according current version you had downloaded from NuGet.
Move the this line <script src="~/Scripts/jquery-3.4.1.min.js"></script> Code at top following location:
To check if jquery has started working or not you just put the following code at the bottom of Create.cshtml.
Press F5 and execute project you will get following screen:
- <script>
- $(document).ready(function(){
- console.log("ready!");
- alert("ready");
- });
- </script>
You can see tin he above screenshot the ready alert box has appeared.
Now switch back to FriendController
Add namespace at top of the file
- // POST: Friend/AddFriend
- [HttpPost]
- public ActionResult AddFriend(FriendModel fm)
- {
- //Write your database insert code / activities
- return RedirectToAction("create");
- }
- @{
- ViewBag.Title = "Create";
- }
- <h2>Create</h2>
- <form id="friendform">
- <table>
- <tr>
- <td>Friend Name</td>
- <td><input id="txtFriendName" name="FriendName" type="text" /></td>
- </tr>
- <tr>
- <td>Phone</td>
- <td><input id="txtPhone" name="Phone" type="text" /></td>
- </tr>
- <tr>
- <td>State</td>
- <td><input id="txtState" name="State" type="text" /></td>
- </tr>
- </table>
- <input id="btnsubmit" type="button" value="Submit"/>
- </form>
- <script>
- $(document).ready(function(){
- console.log("ready!");
- alert("ready");
- });
- </script>
Our next step is to insert Jquery Ajax Form Submit with Serializing because our article title is Asp.Net MVC jQuery AJAX Form Submit using Serialize Form Data into Model.
Switch back to CREATE.CSHTML file to insert AJAX code.
- <script>
- $(document).ready(function () {
- $("#btnsubmit").click(function (e) {
- //Serialize the form datas.
- var valdata = $("#friendform").serialize();
- //to get alert popup
- alert(valdata);
- $.ajax({
- url: "/Friend/AddFriend",
- type: "POST",
- dataType: 'json',
- contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
- data: valdata
- });
- });
- });
- </script>
You can see in the above form where we enter data. On clicking on SUBMIT button this data we should get in controller side ADDFRIEND method.
As I clicked on SUBMIT button alert popup appeared.

German MedinaPosted May 27, 2022, 7:02 PM
Very good article, very useful! Thank you so much
Daniel VegaPosted Dec 18, 2021, 5:45 PM
I love, thanks
Mageshwaran RPosted Nov 15, 2019, 12:17 AM
Super Article...
Sourav Kumar DasPosted Nov 6, 2019, 10:37 PM
Nice Article Sir...