首页 文章

MVC4 RedirectToAction返回HTTP 404

提问于
浏览
3

我的RedirectToAction返回HTTP 404,除了控制器,动作和视图在那里,正确拼写正确的大写字母 . 我在SubscriberController中,我想在CreateTestController中调用一个动作 .

这是我的初始网址:

http://www.localdomain.com/Subscriber/AuthUser

这将启动包含多个表单的页面,我正在使用此页面调用的页面如下:

<form id="btnform7" action="LaunchTestPortal" method="post">
    <input name="__RequestVerificationToken" id="antiforge7" type="hidden" value="rzTdAi...aj501">
    <button title="Create, Edit or Review Training" class="ui...active" id="btnLaunchTestPortal" role="button" style="width: 13em; height: 22px; margin-bottom: 10px;" type="submit">
        <span class="ui-text-only">Create, Edit or Review Training</span>
    </button>
</form>

这成功地在SubscriberController中调用此方法

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LaunchTestPortal()
{
    return RedirectToAction("CreateTestPortal", "CreateTest");
}

这是我想在CreateTestController中调用的方法

[HttpPost]
[ValidateAntiForgeryToken]
public ViewResult CreateTestPortal()
{
    ...
}

在调用之后,这是它返回的地址 http://www.localdomain.com/CreateTest/CreateTestPortal

除了页面结果是找不到HTTP 404 . 所有零件都在那里 . 只是controllerA中的重定向不会调用controllerB中的方法

1 回答

  • 0

    我在评论中添加了评论,以便您可以学习 .

    public class SubscriberController : Controller
    {
        //
        // GET: /Subscriber/
        public ActionResult AuthUser()
        {
            return View();
        }
    
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult LaunchTestPortal()
        {
            return RedirectToAction("CreateTestPortal", "CreateTest");
        }
    }
    
    public class CreateTestController : Controller
    {
        //removed two attributes
        public ViewResult CreateTestPortal()
        {
            var ap = "dh";
            return View();
        }
    }
    

    AuthUser.cshtml

    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>AuthUser</title>
    </head>
    <body>
        @*added Subscriber below*@
        <form id="btnform7" action="/Subscriber/LaunchTestPortal" method="post">
            @*changing next line*@
            @Html.AntiForgeryToken()
            @*<input name="__RequestVerificationToken" id="antiforge7" type="hidden" value="rzTdAi...aj501">*@
            <button title="Create, Edit or Review Training" class="ui...active" id="btnLaunchTestPortal" role="button" style="width: 13em; height: 22px; margin-bottom: 10px;" type="submit">
                <span class="ui-text-only">Create, Edit or Review Training</span>
            </button>
        </form>
    </body>
    </html>
    

    CreateTestPortal.cshtml

    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>CreateTestPortal</title>
    </head>
    <body>
        <div> 
        </div>
    </body>
    </html>
    

相关问题