我有以下使用内部类的 KnockoutJS 映射:
public class Retailer
{
public int RetailerId { get; set; }
public string DemoNumber { get; set; }
public string OutletName { get; set; }
public string OwnerName { get; set; }
public Address Address { get; set; }
public Logging Logging { get; set; }
}
public class Address
{
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zipcode { get; set; }
public string Mobile { get; set; }
public string LandLine { get; set; }
public string Email { get; set; }
}
上面显示了我的模型,我正在使用 KnockoutJS 构建我的网站。
我可以使用ko.mapping
插件绑定控件。但是,当我尝试插入 Retailer 的值时,内部类Address
正在返回null
所有属性的值。
当我在客户端测试东西时,它会显示整个模型值。
IdeaSales.NewRetailer = function () {
$.ajax({
url: '/Retailer/Retailer',
dataType: 'json',
cache: false,
type: "post",
success: function (data) {
viewModel = ko.mapping.fromJS(data);
ko.applyBindings(viewModel);
},
error: function (request, status, error) {
alert(request.responseText);
}
});
}
IdeaSales.InsertRetailer = function () {
var newModel = ko.toJS(viewModel);
$.ajax({
url: '/Retailer/InsertRetailer',
data:viewModel,
cache: false,
type: "post",
success: function (data) {
},
error: function (request, status, error) {
alert(request.responseText);
}
});
}
和:
public int InsertRetailer(Retailer retailer)
{
return new RetailerAppService().InsertRetailer(retailer);
}
问题是我正在获取零售商信息,但对于 Address 类,我正在获取Null
每个值。