2012-10-05 33 views
0

Razor視圖:通字典的形式後,控制器提交

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

控制器動作:

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

有沒有辦法通過模型字典控制器?因爲我的參數始終爲空。

回答

1

您無法通過路由值傳遞字典。你可以這樣做:

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

這將發佈字典。對於複雜物體的想法是一樣的