Return a view from a different area

ŁukaszW.pl picture ŁukaszW.pl · Aug 22, 2010 · Viewed 18.9k times · Source

I have my ASP.NET MVC 2 application divided into few areas. One of them is a default area in the main catalog, and the other is an Account area in the Areas catalog. Now, the problem is that I need to use the same view in controllers from both of these areas.

If they were in the same area, I would just return View("ViewName"), but what can I do to return a view from my default area in a controller from my Account area? Any ideas?

Answer

Darin Dimitrov picture Darin Dimitrov · Aug 22, 2010

You could specify the relative location of the view:

return View("~/Views/YourArea/YourController/YourView.aspx");

But when a view is shared among multiple areas I would recommend you to use the ~/Views/Shared folder which serves better this purpose.