Reputation: 127
I'm working on MVC5.
I already have my controllers and their respective views. If I click on a view and open it on my browser, everything's fine, however, whenever I start the project normally on VS, my browser opens, for example, this link:
http://localhost:50738/Views/Profile/Index.cshtml
However, whenever I open the view directly I have:
http://localhost:50738/Profile or http://localhost:50738/Profile/Index
At the RouteConfig file I just said that I wanted Profile to be shown by default, instead of home. Why does '/Views/' appear on my browser?
code:
namespace WorkTimeManager.Presentation
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Indicators", action = "Index", id = UrlParameter.Optional } );
}
}
}
Upvotes: 0
Views: 4299
Reputation: 252
Its because you have your Start Action set to current page in your web project. So when you start your web app it will try to load the page you are currently viewing in Visual Studio.
To fix this, right click your web project in your solution and click properties, then click on to Web and you will see Start Action - with Current Page radio button selected.
Change this to Specific Page and then type in your homepage URL e.g. http://localhost:50738/Index then everytime you start your web app from Visual Studio it will open on that page instead of trying to open the current page.
Upvotes: 1
Reputation: 28611
When you click on a .cshtml
file ("click on a view"), you're only opening the file that describes that view, you're not opening it via 'mvc'.
MVC doesn't send the .cshtml file to the browser, the controller reads the view and renders it.
So the file in Views/Profile/Page.cshtml
may be rendered by a controller action ProfileController.Page()
(or may not... but would be in the simplest case) for which the URL would be /Profile/Page
This is a brief summary, there are better explanations available of how MVC works.
Upvotes: 0