2011-07-05 24 views
0

我有一堆我控制器內部操作方法各有綁定作爲輸入參數ES:asp.net mvc的強類型與modelbinded輸入參數重定向

[HttpGet] 
public MyActionMethod(MyCustomModel data){ 
... 
} 

... 

public class MyCustomModel{ 
    public int total {get;set;} 
    public string description {get;set;} 
} 

現在,如果我嘗試調用自己的模式傳遞正確的querystring參數集以合成MyCustomModel的方法一切正常。 如果我重定向到action方法使用另一個actionmethod:

RedirectToAction("MyActionMethod", new { total=10, description="test"}); 

它也可以作爲預期。

的問題是,我想才達到某種強類型重定向是這樣的:類似

RedirectToAction(c => c.MyActionMethod, new MyCustomModel{total=10, description="test"}); 

東西可以使用MvcContrib但遺憾的是由於某些原因,擴展可以」提供的擴展方法achived在查詢字符串中組成正確的一組參數,並以不正確的請求結束。

任何想法?

回答

0

你可以做

TempData["MyCustomModel"] = new MyCustomModel{total=10, description="test"}); 

然後

MyCustomModel model = TempData["MyCustomModel"] as MyCustomModel 
在天色重定向到action方法