【问题标题】:improper redirection mvc4不正确的重定向 mvc4
【发布时间】:2012-09-07 00:51:36
【问题描述】:

我是 mvc 新手。

我正在使用 mvc4 移动模板开发网络应用程序。

我有控制器说:

控制器1

和 两种类型的动作

(get,post) : action1, action2, action3

现在,假设我当前的 URL:http://localhost:12345/controller1/action1 然后我点击按钮调用它的发布操作,代码正确执行

 [HttpPost]
 [ActionName("action1")]
 public ActionResult action1_post()
 {
     //some code here
     return RedirectToAction("action2","controller2");
 }

但在浏览器中,它仍然显示此 URL:http://localhost:12345/controller1/action1

这个我看不懂..

谢谢!!

【问题讨论】:

    标签: asp.net-mvc-4


    【解决方案1】:

    您必须将 ActionName 更改为其他名称。这就是为什么它仍然在 url 中显示为 action1 的原因。如果您将其更改为 action1post,那么它应该会更改。例如:

    [HttpPost]
    [ActionName("action1post")]
     public ActionResult action1_post()
    

    【讨论】:

    • 感谢您的回复,但如果我更改我的帖子操作签名,如 public ActionResult action1(guid id){ ... } 并在此操作中,它会将代码重定向到 /controller2/action2... 仍然它将在浏览器地址栏中显示相同的 URL... localhost:12345/controller1/action1
    • 你有controller2和action2吗?如果你有你确定你没有在某个地方返回 View 之前这会导致它保持在同一个视图上。否则,如果我尝试return RedirectToAction("Index", "Home");,我总是会被重定向到此操作。
    • 你确定..我已经调试了很多次代码..控制达到return RedirectToAction(..)语句
    • 也许这个answer 会回答。如果操作需要某些属性,或者调用 httppost 操作可能会出现问题:)
    • 我也试过了 1.. 仍然没有解决...从发布操作重定向时,会出现此问题..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    相关资源
    最近更新 更多