0

I have several action methods that can use the same view. I've tried calling View with eg

return View("~/views/contact/Emails", model);

The view "Emails" exists in the specified directory (Resharper underlines the URL), but when I run the application I get the error "The view '~/views/contact/Emails' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/views/contact/Emails"

1 Answers1

0

Assuming you're inside ContactController, you can simply pass in the name of the view.

return View("Emails", model);

MVC uses routing to find Views, so it doesn't care about the file path, just the name (at least at this point in the request pipeline).

jrummell
  • 42,637
  • 17
  • 112
  • 171
  • That does the trick. Just using the name of the view works. Which suggests that the response at http://stackoverflow.com/questions/5938837/asp-net-mvc-how-to-have-a-controller-in-shared-view is wrong. – Jonathan Allin May 23 '12 at 14:04