Javascript code:
1. Add jQuery reference in your view page.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
2. Add below javascript code.
<script>
$(function () {
$("#btnRLMasterSave").click(function () {
alert("HI");
$.ajax({
url: "/RLMaster/UpdateGLCode",
data: JSON.stringify({ Glcode: $('#Glcode').val(), ReportId: $('#ReportId').val(), HeadName: $('#HeadName').val() }),
type: "POST",
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (data) {
alert(data);
},
error: function () {
alert("Failed");
}
});
});
});
</script>
Controller Code:
[HttpPost]
public ActionResult UpdateGLCode(string Glcode, string ReportId, string HeadName)
{
SqlConnection con = null;
SqlCommand cmd = null;
con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["System.Data.SqlClient"].ToString());
con.Open();
cmd = new SqlCommand("AliUpdateGLCodeInRLMaster", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Criteria1", SqlDbType.VarChar).Value = Glcode;
cmd.Parameters.Add("@Criteria2", SqlDbType.VarChar).Value = ReportId;
cmd.Parameters.Add("@Criteria3", SqlDbType.VarChar).Value = HeadName;
cmd.ExecuteNonQuery();
con.Close();
return Json("Success", JsonRequestBehavior.AllowGet);
}