22

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

4
  • Why don't you want to use RedirectToaction ? Commented Apr 28, 2014 at 8:02
  • @Paul, I just want to avoid adding an extra action method in JobController. Commented Apr 28, 2014 at 8:06
  • 1
    @Ish out of interest if the view is used in multiple controllers why not put it in the shared folder. Then you wont have to use absolute paths. Commented Apr 28, 2014 at 8:29
  • 1
    @Steve yes this is another good idea. Commented Apr 28, 2014 at 9:05

2 Answers 2

56

Just use a relative path based on the Views folder

return View("~/Views/Jobs/Message.cshtml");   
Sign up to request clarification or add additional context in comments.

Comments

8

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");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.