Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 映射在多表单post上失败_Jquery_Asp.net Mvc_Asp.net Mvc 4_Http Post_Model Binding - Fatal编程技术网

Jquery 映射在多表单post上失败

Jquery 映射在多表单post上失败,jquery,asp.net-mvc,asp.net-mvc-4,http-post,model-binding,Jquery,Asp.net Mvc,Asp.net Mvc 4,Http Post,Model Binding,我正在提交两份表格 在我的MVC应用程序中,我有EmailReportVM类。此类有一个名为criteria的变量,其类型为StatsCriteria 当我发布表单时,EmailReporVM中的所有变量都被映射,除了标准 EmailReportVM的变量与frmSendEmail和 StatsCriteria的变量与frmPostToEmailReports 我该怎么做才能让它工作呢 Caller.js: $("#frmSendEmail").validate({ onfocusout

我正在提交两份表格

在我的MVC应用程序中,我有
EmailReportVM
类。此类有一个名为
criteria
的变量,其类型为
StatsCriteria

当我发布表单时,
EmailReporVM
中的所有变量都被映射,除了
标准

EmailReportVM
的变量与
frmSendEmail
StatsCriteria
的变量与
frmPostToEmailReports

我该怎么做才能让它工作呢

Caller.js

$("#frmSendEmail").validate({
    onfocusout: true,
    submitHandler: function (form) {

    //Send the data using post and put the results in a div                   
    $.post(url, $("#frmSendEmail, #frmPostToEmailReports").serialize(), function (data) {
        //do something    
    });
}
public class EmailReportVM
{
    #region Constructors and Methods
    public EmailReportVM() {  }
    #endregion

    #region Properties and Fields
    public string from { get; set; }  
    public string to{ get; set; }
    public string Cc{ get; set; }
    public string Bcc{ get; set; }
    public string Subject { get; set; }
    public string Body { get; set; }
    public string Notes { get; set; }
    public StatsCriteria criteria { get; set; }
    #endregion
}
public class StatsCriteria
{
    #region Constructors and Methods
    public StatsCriteria() { }
    public string Params { get; set; }
    public string AgentId { get; set; }
    public string LicenseNum { get; set; }
    public string AgentFullName { get; set; }
    #endregion
}
控制器

[HttpPost]
public ActionResult Create(EmailReportVM report)
{
    // Here the report object which is of type EmailReportVM has values for all the variables except criteria . 
    HttpResponseMessage response = new HttpResponseMessage();

    try
    {
        using (HttpClient client = new HttpClient())
        {
            ....................          
        }                       
    }
}
EmailReportVM.cs

$("#frmSendEmail").validate({
    onfocusout: true,
    submitHandler: function (form) {

    //Send the data using post and put the results in a div                   
    $.post(url, $("#frmSendEmail, #frmPostToEmailReports").serialize(), function (data) {
        //do something    
    });
}
public class EmailReportVM
{
    #region Constructors and Methods
    public EmailReportVM() {  }
    #endregion

    #region Properties and Fields
    public string from { get; set; }  
    public string to{ get; set; }
    public string Cc{ get; set; }
    public string Bcc{ get; set; }
    public string Subject { get; set; }
    public string Body { get; set; }
    public string Notes { get; set; }
    public StatsCriteria criteria { get; set; }
    #endregion
}
public class StatsCriteria
{
    #region Constructors and Methods
    public StatsCriteria() { }
    public string Params { get; set; }
    public string AgentId { get; set; }
    public string LicenseNum { get; set; }
    public string AgentFullName { get; set; }
    #endregion
}
国家标准

$("#frmSendEmail").validate({
    onfocusout: true,
    submitHandler: function (form) {

    //Send the data using post and put the results in a div                   
    $.post(url, $("#frmSendEmail, #frmPostToEmailReports").serialize(), function (data) {
        //do something    
    });
}
public class EmailReportVM
{
    #region Constructors and Methods
    public EmailReportVM() {  }
    #endregion

    #region Properties and Fields
    public string from { get; set; }  
    public string to{ get; set; }
    public string Cc{ get; set; }
    public string Bcc{ get; set; }
    public string Subject { get; set; }
    public string Body { get; set; }
    public string Notes { get; set; }
    public StatsCriteria criteria { get; set; }
    #endregion
}
public class StatsCriteria
{
    #region Constructors and Methods
    public StatsCriteria() { }
    public string Params { get; set; }
    public string AgentId { get; set; }
    public string LicenseNum { get; set; }
    public string AgentFullName { get; set; }
    #endregion
}

您应该使用正确的模型绑定为复杂对象赋值

检查此项,如果您需要代码方面的帮助,请告诉我


您应该为表单元素使用正确的命名来分配条件属性。请记住,这不是类和类内的类对象的正常属性。因此,要在该对象内设置值,您应该为html元素提供限定名称。例如,参数的输入控件名称应为criteria.Params(在HTMLTank中)。“我试过了,但是运气不好。”大黄蜂-我们能看看风景吗?我很想看看这些表格是如何排列的。你看过链接吗?