Странное поведение 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. Зачем?

1 ответ

Решение

Нет проблем с redirectToAction.

Ты звонишь RedirectToAction("ActionMessageSuccess", new { txt = "Message was sent successfully" });

Поэтому он перенаправлен на действие ActionMessageSuccess со значением txt.

С помощью в ActionMessageSuccess вы возвращаете представление с именем txt, то есть "Сообщение было успешно отправлено", но система не может отправить представление с именем "Сообщение было успешно отправлено".

Другие вопросы по тегам