jquery Ajax 值未在 Mvc 中正确保存
jquery Ajax Value Not Save correctly in 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(Customerinformation customer)
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);
}
}
此函数执行 storepeocedure 并在数据库中保存一些数据。
当我的代码 运行 时,数据未绑定到数据库 int 字段插入 0 和 varchar 字段插入 null。
那样DataBase Data
试试这个
$.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);
}
});
我正在使用 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(Customerinformation customer)
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);
}
}
此函数执行 storepeocedure 并在数据库中保存一些数据。
当我的代码 运行 时,数据未绑定到数据库 int 字段插入 0 和 varchar 字段插入 null。 那样DataBase Data
试试这个
$.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);
}
});