나는 내부 클래스를 사용하여 다음 KnockoutJS 매핑이 다음은 위의 내 모델을 보여줍니다는 내부 클래스의 속성에 null 값을 얻기
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);
}
문제 나 소매 정보를 얻고 있지만 주소 클래스 I는 각 Null
값을 얻고있다.
: viewModel'를, 당신은 '데이터를 게시하려고하지 않았다 newModel'를? 어떤 경우 든 POST를 검사하고 서버로 전송되는 내용을 확인하면 도움이됩니다. 예상 한 것입니까? – Jeroen
MVC 모델 바인딩은 작업의 모든 매개 변수를 초기화 한 다음 게시 된 개체와 함께 게시 된 값을 바인딩하려고 시도합니다. 소매업 자의 주소 기본값은 생성시 null이며 jeroen과 마찬가지로 어쨌든 게시물의 잘못된 값을 전달하는 것처럼 보이므로 소매업자는 모든 것에 대한 기본값이됩니다. –
좋습니다! 그러나 모델을 서버에 전달하는 동안 소매업 자 정보를 전달할 수는 있지만 주소 정보는 null입니다. –