In traditional Asp.Net Web Forms we access a page
using the pages URL like
The UseMvc and UseMvcWithDefaultRoute are used to add a RouterMiddleware instance to the middleware pipeline. Below is a basic sample of how routes are defined in the startup.
app.UseMvc(routes =>
http://localhost/index.aspx
But in Asp.Net MVC we don’t specify the page name or extension in the URL, instead we specify the Controllers action method in the URL and the controller takes care of rendering the corresponding view. Asp.Net Core MVC uses a routing Middleware to map the incoming request to the action method. Routes can be specified either in the startup or as attributes in the Controller / Action methods.
But in Asp.Net MVC we don’t specify the page name or extension in the URL, instead we specify the Controllers action method in the URL and the controller takes care of rendering the corresponding view. Asp.Net Core MVC uses a routing Middleware to map the incoming request to the action method. Routes can be specified either in the startup or as attributes in the Controller / Action methods.
The UseMvc and UseMvcWithDefaultRoute are used to add a RouterMiddleware instance to the middleware pipeline. Below is a basic sample of how routes are defined in the startup.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=ControllerToView}/{id?}");
});
The above simple routing configuration can also be done as follows.
app.UseMvcWithDefaultRoute();
The UseMvcWithDefaultRoute() maps a controller and action route, specifies the default controller as Home and default action as Index.
The above simple routing configuration can also be done as follows.
app.UseMvcWithDefaultRoute();
The UseMvcWithDefaultRoute() maps a controller and action route, specifies the default controller as Home and default action as Index.
No comments:
Post a Comment