【问题标题】:MVC URL RedirectToAction URl has variable and its parameter in UrlMVC URL RedirectToAction URl 在 Url 中有变量及其参数
【发布时间】:2013-05-09 07:39:06
【问题描述】:

我正在将我的操作重定向到另一个带有可选参数并将变量传递给控制器​​的 url

RedirectToAction("action", new { a, c, s,ds});

but my urls loosk like this 

http://localhost:8080/contoller/action?a=1&c=2&s=3&ds=4

but when i directly call teh action the url looks like this 

http://localhost:8080/contoller/action/1/2/3/4

how can i get the same url with redirect ..any suggestion 

【问题讨论】:

    标签: asp.net-mvc-3 model-view-controller asp.net-mvc-routing


    【解决方案1】:

    你试过吗? (我不确定它是否有效)

        RedirectToAction("action", new { a = a, c = c, s = s,ds = ds});
    

    一个肮脏的方法是:

        Redirect("/area/home/action?a=" + a + "&b=" + b + "&c=" + c + "&ds=" + ds);
    

    事实上,我经常使用第二个,因为它可以更清楚地看到所有参数和值。唯一不足的是,如果url有错误,没有警告。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-27
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      • 2015-08-26
      • 2010-10-07
      • 1970-01-01
      • 2015-04-09
      相关资源
      最近更新 更多