我有一个表格,我试图通过 GetJSON 调用发送。当我到达控制器时,与视图绑定的模型是空值。当我得到一个空对象但从来没有一个空值时,我在与返回数据不一致之前遇到了问题。下面是我用来发送表格的代码
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; }
}
唯一没有返回的是序列化中的 ComplexQuery,因为我使用的是 JQuery 对话框,因此它将这些元素从表单中取出。我想我会得到一个 MassEmaikViewModel ,它包含除了 ComplexQuery 之外的所有 vlaues 并且有一个空值,但我只是得到一个空值,因为如果参数甚至没有被初始化。
关于可能导致这种情况的任何想法?
另一件事,我不知道这是否有助于给任何人任何见解,但我可以从表单中发布并将 MassEmailViewModel 作为帖子中的参数,它可以很好地填写除 ComplexQuery 之外的所有值