MVC RedirectToAction 的奇怪行为

发布于 2025-01-06 19:39:15 字数 1201 浏览 4 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩发小公举 2025-01-13 19:39:15

使用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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文