Calling View of different folder from Asp.net mvc4

2020-03-01 05:52发布

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.)

2条回答
虎瘦雄心在
2楼-- · 2020-03-01 06:11

Just use a relative path based on the Views folder

return View("~/Views/Jobs/Message.cshtml");   
查看更多
Root(大扎)
3楼-- · 2020-03-01 06:25

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");
}
查看更多
登录 后发表回答