MVC URL RedirectToAction URl在Url中具有变量及其参数

时间:2013-05-14 21:22:43

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

我将我的Action重定向到另一个带有可选参数的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 

1 个答案:

答案 0 :(得分:0)

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

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

一种肮脏的方法是:

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

事实上我经常使用第二个,因为看到所有参数和值更清楚。唯一不足的是,如果网址中有任何错误,则没有警告。