我的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中的方法
答案 0 :(得分: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>