Jeff Putz
Jeff Putz

Reputation: 14917

ASP.NET Core 2.0 only looking for view in Shared folders

Something non-obvious (or obviously not found via Google-foo) changed in ASP.NET Core 2.0 with regard to how it's finding views. All of the views associated with the generic area route ("{area:exists}/{controller=Home}/{action=Index}/{id?}") will execute their actions and find their associated view as expected, but if I specify a less generic route, like "Forums/Recent/{page?}", it won't find the view. I can't emphasize enough, the code in the controller action fires so it's correctly using the route. It's just not looking for the view in the right place. It's only looking in shared places:

InvalidOperationException: The view 'Recent' was not found. The following locations were searched:
/Areas/Forums/Views/Shared/Recent.cshtml
/Views/Shared/Recent.cshtml

It's not looking in /Areas/Forums/Views/Forum/Recent.cshtml, which by convention matches the controller.

My controllers are not in the same project as the views, if that matters. Again, the controller action executes, but it doesn't even look in the right place for the view. It worked correctly in v1.1.

Upvotes: 6

Views: 842

Answers (1)

Jeff Putz
Jeff Putz

Reputation: 14917

Turns out this is a bug in the view engine that comes up when you have "page" in your route definition. The bits that look for the view don't look in the right place:

https://github.com/aspnet/Mvc/issues/6660

The team has moved the bug into the 2.0.1 release:

https://github.com/aspnet/Mvc/milestone/38

Upvotes: 8

Related Questions