Calling View of different folder from Asp.net mvc4 controller

最后都变了- 提交于 2019-12-18 18:53:53

问题


I hava a View Name "Message" in the Jobs folder of Views. And I want to return that view form an action of different controller, named "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.
(I do not want to use RedirectToaction method here.)


回答1:


Just use a relative path based on the Views folder

return View("~/Views/Jobs/Message.cshtml");   



回答2:


You have to fill the full address for your Message view ("~/Views/Jobs/Message.cshtml"):

[HttpPost]
public ActionResult Save()
{
    TempData["message"] = "Save successfully";
    return View("~/Views/Jobs/Message.cshtml");
}


来源:https://stackoverflow.com/questions/23335555/calling-view-of-different-folder-from-asp-net-mvc4-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!