Reputation: 31
Why can't I find the controllers folder for visual studio 2017 for Mac? I'm trying to follow this tutorial: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app-mac/start-mvc?view=aspnetcore-2.1 And on the part of the controllers folder, I don't have it on my solutions explorer. I have see a post similar to this about not finding the controllers folder but that the solution didn't work for me. I'm not sure if I could make the controllers folder show up. Here's how my solution explorer looks like.my solution explorer I need to just find the controllers folder to show like this: screenshot with a controllers folder. Thank you in advance.
Upvotes: 3
Views: 7672
Reputation: 2907
It seems that you created a Razor Page Project instead of an MVC project. That's why you don't see the controller folder.
I don't know about Visual Studio for Mac, but in visual studio for Windows when I create a new .NET Core Web App, I am then promted to chose between Web application (ie Razor Page), Web Application MVC, empty and more
The easiest solution is to start over and create and create a new MVC project.
But can keep your existing project if you want and can add a Controllers, a Views folder, a Models folder. Add the _Layout and ViewStart views and add the controllers and views that you need.
I you do that you have to configure the routing of MVC by replacing in Startup.cs
app.UseMvc();
by
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Upvotes: 7