7

Basically I've just created an Area in my ASP.NET MVC4 application. It all works great etc, however when I want to return a PartialView as shown below:

return PartialView("_ImportSessionsTable", viewModel);

(not that the above call is called from the area(admin) view) I get the following error:

The partial view '_ImportSessionsTable' was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/ImportSessions/_ImportSessionsTable.aspx

~/Views/ImportSessions/_ImportSessionsTable.ascx

~/Views/Shared/_ImportSessionsTable.aspx

~/Views/Shared/_ImportSessionsTable.ascx

~/Views/ImportSessions/_ImportSessionsTable.cshtml

~/Views/ImportSessions/_ImportSessionsTable.vbhtml

~/Views/Shared/_ImportSessionsTable.cshtml

~/Views/Shared/_ImportSessionsTable.vbhtml

The thing is: as far as I can see it isn't looking for the view in the area folder (admin) which is where I have the view stored. How can I get it to look there? Whenever I call return View(); it works fine so it's only when I specify the view as a string.

Jordan Axe
  • 3,823
  • 6
  • 20
  • 27

2 Answers2

20

How can I get it to look there?

You could specify the full location of the partial to be rendered:

return PartialView("~/Areas/Admin/Views/ImportSessions/_ImportSessionsTable.cshtml", viewModel);
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 1
    Well I ended up following your example and it works now by the following path: ~/Areas/Admin/Views/ImportSessions/_ImportSessionsTable.cshtml I would just assume that it's possible for it to automatically look in the area it's being called in. – Jordan Axe Oct 20 '13 at 13:15
0

You could also consider overriding where the viewengine searches for views, but that might be a little extreme for what you're looking for. See here: Link

Community
  • 1
  • 1
dwbartz
  • 886
  • 10
  • 13