jquery Ajax值在Mvc中未正确保存



我正在使用Jquery Ajax代码

$("#savecustomer").click(function() {
  var customer = {};
  debugger;
  customer.Customerid = $("#userid").text();
  customer.PhoneNo = $("#txtphoneno").val();
  customer.Email = $("#txtemail").val();
  customer.Password = $("#txtpwd").val();
  customer.Name = $("#txtname").val();
  customer.Shiping_Address = $("#txtsa").val();
  customer.Pin = $("#txtpin").val();
  $.ajax({
    url: '/Home/AddCustomerInfo',
    method: 'Post',
    dataType: "json",
    data: '{customer: ' + JSON.stringify(customer) + '}',
    success: function() {
      alertify.log("Your Data saved Successfully...", "Success", 3000);
    },
    error: function() {
      alertify.log("Data Not Save ......", "error", 3000);
    }
  });
});

和Mvc控制器功能名称

public void AddCustomerInfo(客户信息客户)

   public void AddCustomerInfo(Customerinformation customer)
    {
        using (TestEntities db = new TestEntities())
        {
            db.spAddCustomer(customer.Customerid, customer.PhoneNo, customer.Email, customer.Password, customer.Name, customer.Shiping_Address, customer.Pin);
        }
    }

该函数执行存储过程并在数据库中保存一些数据。

当运行我的代码时,数据不会被带到数据库int字段insert 0和varchar字段insert null。类似于数据库数据

试试这个

 $.ajax({
            url: '@Url.Action("AddCustomerInfo", "Home")',
            data: JSON.stringify({ customer: customer }),
            dataType: 'json',
            type: 'POST',
            contentType: "application/json; charset=utf-8",
            success: function() {
            alertify.log("Your Data saved Successfully...", "Success", 3000);
            },
            error: function() {
            alertify.log("Data Not Save ......", "error", 3000);
            }
        });

相关内容

  • 没有找到相关文章

最新更新