Skip to main content

Routing in aso.net mvc

Routing helps you to define user friendly URL structure and map those URL structure to the controller.
For instance let's say we want that when any user types "http://localhost/View/ViewCustomer/" , it goes to the "Customer" Controller and invokes "DisplayCustomer" action.This is defined by adding an entry in to the "routes" collection using the "maproute" function. Below is the under lined code which shows how the URL structure and mapping with controller and action is defined.


The route mapping code is written in "RouteConfig.cs" file and registered using "global.asax" application start event.
Yes , you can , you just need to make two entries with different key names and specify the same controller and action.
Explain attribute based routing in MVC?

This is a feature introduced in MVC 5. By using the "Route" attribute we can define the URL structure. For example in the below code we have decorated the "GotoAbout" action with the route attribute. The route attribute says that the "GotoAbout" can be invoked using the URL structure "Users/about".


What is the advantage of defining route structures in the code?
Most of the time developers code in the action methods. Developers can see the URL structure right upfront rather than going to the "routeconfig.cs" and see the lengthy codes. For instance in the below code the developer can see right upfront that the "GotoAbout" action can be invoked by four different URL structure.

This is much user friendly as compared to scrolling through the "routeconfig.cs" file and going through the length line of code to figure out which URL structure is mapped to which action


Comments

Popular posts from this blog

Gemini software Dot net interview question for experienced

Gemini Interview questions 4-8 year experienced Dot net professional Gemini Interview questions 4-8 year experienced Dot net professional 1,Asp .net mvc request life cycle. 2,How routing works 3,Where codes for routing are written 4,What is attribute based routing in aap.net Mvc 5,Is multiple routes possible on a single action method. 6,What is action filters. 7,what is authentication and authorization filters 8,What are the types of authentication 8,What is the use of data annotation 9,Can we fire data annotation in client side. 10,What is model binding 11,what are Html helpers

Angular 4 Interview questions

Angular 4 Interview questions experienced Angular 4 Interview questions Animations Questions: How do you define transition between two states in Angular? How do you define a wildcard state? Architecture Questions: What is a good use case for ngrx/store? Can you talk about a bug related to a race condition, how to solve it and how to test it? API Questions: What does this code do: @ HostBinding ( ' class.valid ' ) isValid ; < div * ngIf = ' someObservableData | async as data; else loading ' >{{data}}</ div > < ng-template # loading > Loading Data... </ ng-template > Why would you use renderer methods instead of using native element methods? What is the point of calling renderer.invokeElementMethod(rendererEl, methodName)? How would you control size of an element on resize of the window in a component? What would be a good use for NgZone service? How would you protect a component being activated throu...

Localization in angular4 by fetching data from server using VS2017

Localization in angular4 by fetching data from server using VS2017 Localization  in angular4 by fetching data from server using VS2017 1,This is my webapi controller from where the data for localization is fetched //This is our webApi COntroller  // GET: api/local/5    [HttpGet, Route("api/local/{name}")]         public IDictionary Get(string name)         {                             Dictionary dict = new Dictionary ();                 dict.Add("user01", "Nombre");//Name                 dict.Add("user02", "Nombre del Padre");//Father Name                 dict.Add("user03", "Direccion postal");//Postal Address                 return dict.ToDictionary(p => p.Ke...