【问题标题】:asp.net mvc strongly-typed redirect with modelbinded input parameter带有模型绑定输入参数的 asp.net mvc 强类型重定向
【发布时间】:2011-09-28 22:56:30
【问题描述】:

我的控制器中有一堆动作方法,每个方法都有自己的模型绑定为输入参数 es。:

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

...

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

现在,如果我尝试调用传递正确的查询字符串参数集的方法来组成 MyCustomModel,一切都会按预期工作。 如果我使用以下方式从另一个动作方法重定向到动作方法:

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

它也可以按预期工作。

问题是我想实现某种强类型重定向,例如:

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

使用 MvcContrib 提供的扩展方法可以实现类似的效果,但不幸的是,由于某种原因,扩展无法在查询字符串中组成正确的参数集,从而导致错误的请求。

有什么想法吗?

【问题讨论】:

    标签: asp.net-mvc redirect query-string strong-typing


    【解决方案1】:

    你可以的

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

    然后

    MyCustomModel model = TempData["MyCustomModel"] as MyCustomModel
    

    在被重定向到的操作方法中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-30
      • 2010-10-13
      • 1970-01-01
      • 1970-01-01
      • 2011-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多