0

I created a new "asp.net core web application" project. NOT MVC!.

i see in the stratup.cs, in configure method:

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller}/{action=Index}/{id?}");
});

question a: the url mapped directly to razor pages ('/Index' => /Pages/Index.cshtml). and there is no IController in the entire project, What the routing of MVC doing here?

quetstion b: if i want additionaly custom routing, can I do this without turn all routing to MVC methodology?

4
  • 1
    answers to both questions exist in documentation: Routing in ASP.NET Core and Routing to Controller Actions Commented Nov 28, 2017 at 21:29
  • you can probably use attribute routing too Commented Nov 28, 2017 at 21:31
  • you can remove the routes.MapRoute part and pages will still work Commented Nov 28, 2017 at 21:51
  • @Shyju so its a mistake of the template developers? Commented Nov 28, 2017 at 21:53

1 Answer 1

1

Razor pages are a feature of ASP.Net MVC, hence the dependency on certain services and middleware, but they offer a lightweight alternative to the traditional Model-Controller-View approach. A Razor view represents the View and a code-behind class represents the Model and Controller.

By convention:

/Pages/Index.cshtml routes to / or /Index
/Pages/Contact.cshtml routes to /Contact
/Pages/Store/Contact.cshtml routes to /Store/Contact

For a full answer, you should probably read the documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

thank! but i'm not fund any official documentation for this convention.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.