gpt4 book ai didi

asp.net-mvc-3 - 表单提交后将字典从 View 传递到 Controller

转载 作者:行者123 更新时间:2023-12-02 22:27:29 25 4
gpt4 key购买 nike

Razor View :

@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>
}

Controller Action :

[HttpPost]
public string Move(Dictionary<Sales_Order_Collected, string> dict) {
return "";
}

有没有办法将模型字典传递给 Controller ​​?因为我的参数总是空的。

最佳答案

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

@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"/>
}

这将发布词典。复杂对象的思路是一样的

关于asp.net-mvc-3 - 表单提交后将字典从 View 传递到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12745867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com