GetJSON 호출로 보내려는 양식이 있습니다. 컨트롤러에 도달하면보기에 연결된 모델이 null 값이됩니다. 나는 empy 객체를 얻었지만 null 값을 얻지 못했을 때 데이터 반환과 관련하여 문제가있었습니다. 아래는 내가 양식 아래양식 직렬화 GetJSON이 null 모델을 반환합니다.
var cqvdata = $("form").serialize();
$.getJSON('@Url.Action("GetEmailByAdvanced", "CustomerEmails")', { cqv: cqvdata }, function (contacts) {
var emails = "";
$.each(contacts, function (index, contact) {
$('#BCCText').tagit('createTag', contact.Email)
});
return false;
});
에게 보내 사용하고있는 코드는 내가 컨트롤러 측 여기
public JsonResult GetEmailByAdvanced(MassEmailViewModel cqv)
{
}
에 어떤되는 것은 내가 문자열
으로 내 주장을 켜면 내가 결과를 얻을 것입니다"EmailFromAddressID=1&ToAddresses=&CCAddresses=bclairmont%40harr.com&BCCAddresses=adunn%40harr.com&Subject=&Body="
는 아래 MassEmailViewModelClass 및 모든 하위 클래스입니다
public class MassEmailViewModel
{
public MassEmailViewModel()
{
ComplexQuery = new CustomerQueryViewModel();
}
public int EmailFromAddressID { get; set; }
public CustomerQueryViewModel ComplexQuery { get; set; }
public string ToAddresses { get; set; }
public string CCAddresses { get; set; }
public string BCCAddresses { get; set; }
public string Subject { get; set; }
[AllowHtml]
public string Body { get; set; }
}
public class CustomerQueryViewModel
{
public CustomerQueryViewModel()
{
Products = new List<CustomerProductQueryProduct>();
Details = new List<CustomerQueryDetail>();
}
public Boolean IncludeOnAll { get; set; }
public Boolean ExcludeOnAll { get; set; }
public List<CustomerProductQueryProduct> Products { get; set; }
public List<CustomerQueryDetail> Details { get; set; }
}
public class CustomerProductQueryProduct
{
public CustomerProductQueryProduct()
{
ProductDetails = new List<CustomerProductQueryProductDetail>();
ProductVersions = new List<ProductVersion>();
}
public ProductType ProductType { get; set; }
public Boolean Exclude { get; set; }
public Boolean Include { get; set; }
public int VersiondID { get; set; }
public List<CustomerProductQueryProductDetail> ProductDetails { get; set; }
public List<ProductVersion> ProductVersions { get; set; }
}
public class CustomerProductQueryProductDetail
{
public ProductTypeDetail ProductDetail { get; set; }
public Boolean Exclude { get; set; }
public Boolean Include { get; set; }
public string Value { get; set; }
public string Value2 { get; set; }
}
public class CustomerQueryDetail
{
public string Description { get; set; }
public string Type { get; set; }
public Boolean Exclude { get; set; }
public Boolean Include { get; set; }
public string Value { get; set; }
public string Value2 { get; set; }
}
JQuery 대화 상자를 사용하고 있기 때문에 serialize에서 ComplexQuery가 반환되는 유일한 경우는 해당 요소를 양식 밖으로 가져옵니다. 내가 woudl 내가 생각하지만, ComplexQuery하지만 null을 가지고있는 모든 vlaues와 함께 MassEmaikViewModel을 얻을 수 있지만 인수가 초기화되지 않은 경우에도 그냥 null을 얻을 것으로 생각합니다.
어떤 원인 일 수 있습니까?
다른 사람이 어떤 통찰력을 주는지는 모르겠지만 양식에서 게시 할 수 있고 게시물의 인수로 MassEmailViewModel을 가질 수 있으며 예외를 제외한 모든 값을 채우지 않습니다. ComplexQuery의 경우