【发布时间】:2016-08-02 02:51:26
【问题描述】:
我正在使用 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
【问题讨论】:
-
将您的
data选项更改为data: customer,,它会很好地绑定,但是您的代码表明您的视图存在许多其他问题。如果您正确生成它,那么它只是data: $('form').serialize()
标签: jquery ajax asp.net-mvc c#-4.0 entity-framework-4