表单提交后将字典从视图传递到控制器

Sll*_*lix 3 routevalues razor asp.net-mvc-3

剃刀视图:

@using (Html.BeginForm("Move", "Details", new { dict= dictionary}, FormMethod.Post)) {
    //table with info and submit button
    //dictionary => is a dictionary of type <Sales_Order_Collected, string>
}
Run Code Online (Sandbox Code Playgroud)

控制器动作:

[HttpPost]
public string Move(Dictionary<Sales_Order_Collected, string> dict) {
    return "";
}
Run Code Online (Sandbox Code Playgroud)

有没有办法将模型字典传递给控制器​​?因为我的参数始终为空。

kar*_*una 6

您不能通过路由值传递字典。你可以这样做:

@using (Html.BeginForm("Move", "Details", null, FormMethod.Post)) {
    <input type="text" name="[0].Key" value="first key"/>
    <input type="text" name="[0].Value" value="first value"/>

    <input type="text" name="[1].Key" value="second key"/>
    <input type="text" name="[1].Value" value="second value"/>
}
Run Code Online (Sandbox Code Playgroud)

这将发布字典。对于复杂对象的想法是一样的