MVC RedirectToAction 的奇怪行为
我有以下 UserController 方法:
public ActionResult DeleteThread(int RootMessageID)
{
_repository.DeleteMessageThread(RootMessageID);
return RedirectToAction("ActionMessageSuccess", new { txt = "Message was sent successfully" });
}
public ActionResult ActionMessageSuccess(string txt)
{
return View(txt);
}
有 cshtml 页面(在 Views\User 中):
@model System.String
@{
ViewBag.Title = "SendMessageSuccess";
Layout = "~/Views/Shared/_LayoutUser.cshtml";
}
<h2>@Model</h2>
但我得到:
The view 'Message was sent successfully' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/User/Message was sent successfully.aspx
~/Views/User/Message was sent successfully.ascx
~/Views/Shared/Message was sent successfully.aspx
~/Views/Shared/Message was sent successfully.ascx
~/Views/User/Message was sent successfully.cshtml
~/Views/User/Message was sent successfully.vbhtml
~/Views/Shared/Message was sent successfully.cshtml
~/Views/Shared/Message was sent successfully.vbhtml
在调用 DeleteThread 之后。为什么?
I have the following UserController methods:
public ActionResult DeleteThread(int RootMessageID)
{
_repository.DeleteMessageThread(RootMessageID);
return RedirectToAction("ActionMessageSuccess", new { txt = "Message was sent successfully" });
}
public ActionResult ActionMessageSuccess(string txt)
{
return View(txt);
}
have cshtml page (in Views\User):
@model System.String
@{
ViewBag.Title = "SendMessageSuccess";
Layout = "~/Views/Shared/_LayoutUser.cshtml";
}
<h2>@Model</h2>
but I got:
The view 'Message was sent successfully' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/User/Message was sent successfully.aspx
~/Views/User/Message was sent successfully.ascx
~/Views/Shared/Message was sent successfully.aspx
~/Views/Shared/Message was sent successfully.ascx
~/Views/User/Message was sent successfully.cshtml
~/Views/User/Message was sent successfully.vbhtml
~/Views/Shared/Message was sent successfully.cshtml
~/Views/Shared/Message was sent successfully.vbhtml
after call DeleteThread. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用redirectToAction没有问题。
您正在调用
RedirectToAction("ActionMessageSuccess", new { txt = "Message was sent successfully" });
因此它重定向到具有 txt 值的操作 ActionMessageSuccess。
在 ActionMessageSuccess 中,您将返回一个名为 txt 的视图,即“消息已成功发送”,但系统无法归档名为“消息已成功发送”的视图。
There is no problem with redirectToAction.
You are calling
RedirectToAction("ActionMessageSuccess", new { txt = "Message was sent successfully" });
So it redirected to action ActionMessageSuccess with txt value.
With in ActionMessageSuccess you are returning a view with name txt i.e. "Message was sent successfully", but system unable to file a view with name "Message was sent successfully".