javascript - Call an Action method using Ajax in MVC4 -
action method doesn't fire in code. can please show me error. :)
here code..
<script type="text/javascript"> $("#btnsave").click(function () { var contactid = $("#txtcontactid").val(); var company = $("#txtcompany").val(); var status = $("#cmbstatus").val(); var isactive = $("#isactive").is(':checked'); var comments = $("#txacomments").val(); var country = $("#cmbcountry").val(); var address1 = $("#txtaddress1").val(); var address2 = $("#txtaddress2").val(); var city = $("#txtcity").val(); var state = $("#txtstate").val(); var postalcode = $("#txtpostalcode").val(); var vatno = $("#txtvatno").val(); var regno = $("#txtregno").val(); var phone = $("#txtphone").val(); var email = $("#txtemail").val(); $.ajax({ url: "customer/insertcustomer", data: { 'contactid': contactid, 'company': company, 'status': status, 'isactive': isactive, 'comments': comments, 'country': country, 'address1': address1, 'address2': address2, 'city': city, 'state': state, 'postalcode': postalcode, 'vatno': vatno, 'regno': regno, 'phone': phone, 'email': email }, datatype: "json", type: 'post', success: function (data) { alert("successfully inserted!"); }, error: function () { alert("error"); } }); });
here action method..
public actionresult insertcustomer(string contactid, string company, int status, bool isactive, string comments, int country, string address1, string address2, string city, string state, string postalcode, string vatno, string regno, string phone, string email) { bool process = false; return json(process, jsonrequestbehavior.allowget); }
you need set [httppost] attribute:
[httppost] public actionresult insertcustomer(string contactid, string company, int status, bool isactive, string comments, int country, string address1, string address2, string city, string state, string postalcode, string vatno, string regno, string phone, string email) { bool process = false; return json(process, jsonrequestbehavior.allowget); }
Comments
Post a Comment