Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling View of different folder from Asp.net mvc4 controller

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

like image 932
Ishtiaq Avatar asked Apr 28 '14 07:04

Ishtiaq


People also ask

Can I send multiple view models to a view from controller?

In MVC we cannot pass multiple models from a controller to the single view.

How do I return a different controller view?

In this example, we have created a sample login page, and based on Login we are redirecting to another controller action method. Open Visual Studio. Click on the file in the menu and select new Project . Select new project type.


2 Answers

Just use a relative path based on the Views folder

return View("~/Views/Jobs/Message.cshtml");   
like image 56
Murali Murugesan Avatar answered Sep 30 '22 18:09

Murali Murugesan


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");
}
like image 39
Adiono Avatar answered Sep 30 '22 17:09

Adiono