Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.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
C# MVC邮政赢得';t绑定模型…结果为空_C#_Asp.net Mvc_Asp.net Mvc 4_Model - Fatal编程技术网

C# MVC邮政赢得';t绑定模型…结果为空

C# MVC邮政赢得';t绑定模型…结果为空,c#,asp.net-mvc,asp.net-mvc-4,model,C#,Asp.net Mvc,Asp.net Mvc 4,Model,我已经阅读了许多与此相关的报道问题,没有一个解决了我的问题 型号: public class MySoftwareResults { public Shopping_MachineInformation MachineInformation { get; set; } public ShoppingUserInformation UserInformation { get; set; } public List<Shopping_MySoftwareResults&

我已经阅读了许多与此相关的报道问题,没有一个解决了我的问题

型号:

public class MySoftwareResults
{
    public Shopping_MachineInformation MachineInformation { get; set; }
    public ShoppingUserInformation UserInformation { get; set; }
    public List<Shopping_MySoftwareResults> ApplicationsList { get; set; }
    public string Requester { get; set; }

    public MySoftwareResults()
    {
        MachineInformation = new Shopping_MachineInformation();
        UserInformation = new ShoppingUserInformation();
        ApplicationsList = new List<Shopping_MySoftwareResults>();
        Requester = "";
    }
}
我尝试使用Fiddler,但是我找不到任何东西来反映表单加载时传递的模型数据


我被难住了。

感谢Stephen Muecke指导我更好地理解建模是如何在表单中工作的。通过执行以下操作,我可以将数据绑定到POST调用

对于我没有显示数据的模型,但需要将它们绑定到我所做的文章:

<div style="display: none">
            @Html.EditorFor(x=>x.MachineInformation)
            @Html.EditorFor(x=>x.UserInformation)
        </div>

@Html.EditorFor(x=>x.MachineInformation)
@EditorFor(x=>x.UserInformation)
对于我想要显示数据的模型,我做到了:

@for (int i = 0; i < Model.ApplicationsList.Count; i++)
                {
                    <tr>
                        <td>
                            @Html.LabelFor(m => m.ApplicationsList[i].Software, new {@class = "form-controller"})
                        </td>
                        <td>@Html.LabelFor(m => m.ApplicationsList[i].Cost, new {@class = "form-controller"})</td>
                        <td>
                            @Html.LabelFor(m => m.ApplicationsList[i].RequiresApproval, new {@class = "form-controller"})
                        </td>
                        <td>@Html.LabelFor(m => m.ApplicationsList[i].Status, new {@class = "form-controller"})</td>
                        <td>
                            <input type="checkbox" id="Selected" name="Selected" value="@Model.ApplicationsList[i].CollectionID"/>
                        </td>
                    </tr>
                }
@for(int i=0;im.ApplicationsList[i]。软件,新{@class=“form controller”})
@LabelFor(m=>m.ApplicationsList[i]。成本,新{@class=“form controller”})
@LabelFor(m=>m.ApplicationsList[i].RequiresApproval,新{@class=“form controller”})
@LabelFor(m=>m.ApplicationsList[i]。状态,新{@class=“form controller”})
}

当我点击提交时,我的模型在控制器中填充

非常确定,在通过Request.Form[]使用值之前,您需要为值赋予“name”属性。不确定这是否适用于内置的Html.LabelForModel。不要这么认为。最初我是用复选框解决问题的。我已经弄明白了,请求。表单[]包含了这些数据。在这个示例中,我构建了一个用于解决绑定到文章的模型的复选框问题的模型。但在我的应用程序中,它不是。您生成的html与您的模型没有关系。您生成的唯一输入具有
name=“Selected”
,并且只会绑定到
public ActionResult MySoftwareResults(bool[]Selected)
,这将是无用的。请参阅了解如何绑定到集合。表单只会发回成功控件的名称/值对(
)啊!哼!我就快把它绑起来了。我已设法使应用程序列表绑定。如何让其他子模型绑定?我不想显示数据,只是想把它传输到控制器?我尝试了@Html.hiddenformation(x=>x.MachineInformation),但没有成功。
<div style="display: none">
            @Html.EditorFor(x=>x.MachineInformation)
            @Html.EditorFor(x=>x.UserInformation)
        </div>
@for (int i = 0; i < Model.ApplicationsList.Count; i++)
                {
                    <tr>
                        <td>
                            @Html.LabelFor(m => m.ApplicationsList[i].Software, new {@class = "form-controller"})
                        </td>
                        <td>@Html.LabelFor(m => m.ApplicationsList[i].Cost, new {@class = "form-controller"})</td>
                        <td>
                            @Html.LabelFor(m => m.ApplicationsList[i].RequiresApproval, new {@class = "form-controller"})
                        </td>
                        <td>@Html.LabelFor(m => m.ApplicationsList[i].Status, new {@class = "form-controller"})</td>
                        <td>
                            <input type="checkbox" id="Selected" name="Selected" value="@Model.ApplicationsList[i].CollectionID"/>
                        </td>
                    </tr>
                }