[英]Calling View of different folder from Asp.net mvc4 controller
I hava a View Name "Message" in the Jobs folder of Views. 我在Views的Jobs文件夹中有一个View Name“Message”。 And I want to return that view form an action of different controller, named "MarketController" 我希望从不同控制器的动作返回该视图,名为“MarketController”
public class MarketController : Controller
{
[HttpPost]
public ActionResult Save()
{
// logic to save the record
TempData["message"] = "Save successfully";
return View("Message");
}
}
The problem is that the "Message" view is not in the View of Market, how can i return that view from MarketController. 问题是“消息”视图不在市场视图中,我如何从MarketController返回该视图。
(I do not want to use RedirectToaction method here.) (我不想在这里使用RedirectToaction方法。)
只需使用基于Views
文件夹的相对路径
return View("~/Views/Jobs/Message.cshtml");
You have to fill the full address for your Message view ("~/Views/Jobs/Message.cshtml"): 您必须填写消息视图的完整地址(“〜/ Views / Jobs / Message.cshtml”):
[HttpPost]
public ActionResult Save()
{
TempData["message"] = "Save successfully";
return View("~/Views/Jobs/Message.cshtml");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.