Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of Route Name in Routes in Asp.Net MVC

The default Asp.Net MVC route is :

routes.MapRoute(
  "Default", // Route name
  "{controller}/{action}/{id}", // URL with parameters
   new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
);

And, If we want to make custom routes then we can do that also, like given below :

routes.MapRoute(
  "Privacy", // Route name
  "privacy",
   new { controller = "Home", action = "Privacy" }
);

So, my question is that what is the purpose of 'Route name' in routes given above or can we have more then one Routes with same 'Route name'.

like image 892
Kartikeya Khosla Avatar asked Jul 21 '14 06:07

Kartikeya Khosla


People also ask

What is the use of route name in MVC?

Route Name: A route is a URL pattern that is mapped to a handler. A handler can be a controller in the MVC application that processes the request. A route name may be used as a specific reference to a given route.

How route is defined in MVC?

Routing in ASP.NET MVC cs file in App_Start Folder, You can define Routes in that file, By default route is: Home controller - Index Method. routes. MapRoute has attributes like name, url and defaults like controller name, action and id (optional).

What is the use of route config in MVC?

In MVC, routing is a process of mapping the browser request to the controller action and return response back. Each MVC application has default routing for the default HomeController. We can set custom routing for newly created controller. The RouteConfig.

Which method is used for adding routes to an MVC application?

When an MVC application first starts, the Application_Start() method is called. This method, in turn, calls the RegisterRoutes() method. The RegisterRoutes() method creates the route table. The default route table contains a single route (named Default).

What is routing in ASP NET MVC?

ASP.NET MVC - Routing. Routing is the process of directing an HTTP request to a controller and the functionality of this processing is implemented in System.Web.Routing. This assembly is not part of ASP.NET MVC. It is actually part of the ASP.NET runtime, and it was officially released with the ASP.NET as a .NET 3.5 SP1.

What is maproute in MVC?

Inside the call to UseMvc, MapRoute is used to create a single route, which we'll refer to as the default route. Most MVC apps will use a route with a template similar to the default route.

How do I create a custom route in MVC?

Routing in ASP.NET MVC Routing in MVC is easy, here we have Route.Config.cs file in App_Start Folder, You can define Routes in that file, By default route is: Home controller - Index Method.

What are the different types of routing in ASP NET Core?

ASP.NET Core apps can mix the use of conventional routing and attribute routing. It's typical to use conventional routes for controllers serving HTML pages for browsers, and attribute routing for controllers serving REST APIs. Actions are either conventionally routed or attribute routed.


1 Answers

It is a shorthand way to reference to the route, by using

@Html.RouteLink("Privacy");

Here an article on ASP.NET about routing, which helped me a lot...

ASP.NET MVC Routing Overview (C#)

like image 83
Ferox Avatar answered Oct 25 '22 02:10

Ferox