Submit Form using jQuery in ASP.Net MVC

In this article we will learn with an example, Submit Form using jQuery in ASP.Net MVC
This article will explain how to Submit Form using jQuery in ASP.Net MVC.


The Controller consists of two Action methods.

Action method for handling GET operation

Inside this Action method, simply the View is returned.

Action method for handling AJAX POST operation

This Action method handles the Ajax Form submission and it accepts the value of the Form elements as parameter.

public class HomeController : Controller
    public ActionResult Index()
        return View();
    public ActionResult Index(string firstName, string middleName)
        if (!string.IsNullOrEmpty(firstName) && !string.IsNullOrEmpty(middleName))
            string name = string.Format(“Name: {0} {1}”, firstName, middleName);
            return Json(true);
        return Json(false);


The View consists of an HTML Form which has been created using the Html.BeginForm method with the following parameters.

ActionName – Name of the Action. My action name is Index.

ControllerName – Name of the Controller. My controller name is Home.

FormMethod – It specifies the Form Method i.e. GET or POST. In this case it will be set to POST.

    Layout = null;
<!DOCTYPE html>
    <meta name=”viewport” content=”width=device-width”/>
    @using (Html.BeginForm(“Index”, “Home”, FormMethod.Post, new { @id = “myFormSubmit” }))
                <td>First Name: </td>
                <td><input type=”text” id=”txtFirstName”/></td>
                <td>Last Name: </td>
                <td><input type=”text” id=”txtMiddleName”/></td>
                <td><input type=”button” value=”Submit” onclick=”AjaxFormSubmit()”/></td>
    <script type=”text/javascript” src=””></script>
    <script type=”text/javascript”>
        function AjaxFormSubmit() {
            //Set the URL.
            var url = $(“#myFormSubmit”).attr(“action”);
            //Add the Field values to FormData object.
            var formData = new FormData();
            formData.append(“firstName”, $(“#txtFirstName”).val());
            formData.append(“middleName”, $(“#txtMiddleName”).val());
                type: ‘POST’,
                url: url,
                data: formData,
                processData: false,
                contentType: false
            }).done(function (response) {
                if (response) {
                    alert(“Form successfully submitted!”);
                else {
                    alert(“Invalid Form data!”);



Leave a Reply

Your email address will not be published.