Home

Wednesday, 6 July 2016

Call controller Method after a Click with Parameter using jQuery $.ajax() and $.post()

Ajax Code
$('#btnSave').click(function () {
    var name = $('#txtname').val();
    var fname = $('#txtfname').val();
    $.ajax({
        url: "/Home/SaveRecord",
        data: { 'Name' : name, 'Fname' : fname },
        type: "post",
        cache: false,
        success: function (Status) {
            alert("Save Successfully");
        },
        error: function (status) {
            alert("Saving failed");
        }
    });
});

Controller Code
[HttpPost]
        public ActionResult SaveRecord(string Name, string Fname){
        }

No comments:

Post a Comment