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 "";
}
Is there a way to pass the model dictionary to the controller? Because my parameter is always null.
you can not pass dictionary through route values. You can do something like this:
@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"/>
}
This will post Dictionary. The idea for complex objects is the same
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With