Gives solution for any Error occurs in any Programming Language, .Net Core 3.1, 3.0, C#,Asp.Net,Sqlserver,MVC,Java,Php,Html,Css,Jquery,errors and solutions,Latest News,Technology

Monday, 25 January 2016

Explain Routing Concept In MVC 3 and MVC 4

No comments :
Here I will explained about Routing in MVC 
Routing is a process of matching a pattern. It should monitor incoming request URL with the Route table URL.
You can register one/more URL patterns into the Route Table. This will be done at Application_Start event.
Define a route:
Solution Explorer -> App_Start Folder -> RouteConfig.cs

In above code “controller = "Home", action = "Index", id = UrlParameter.Optional” these are default parameters will be taken if you will not specify any values for controller/action/id defined in the pattern.

Routing engine search for the matching URL from the Route Table for the every incoming request, if it is match forward this request to the appropriate controller and action. If it doesn’t match with the Route Table returns a 404 HTTP error.
URL Pattern
Parameters
Default / Optional Parameters Used
Controller: Home,Action: Index,Id: Optional
Yes
Controller: Home,Action: Index,Id: Optional
Yes
Controller: Home,Action: Index,Id: Optional
No, Here you passed both the parameters for the controller and action
Controller: Home,Action: Index,Id: 5
No, Here optional parameter is also passed
Controller: Home,Action: Index,Id: 5
Wrong. Because you passed more parameter values than what we specified in the route map.


No comments :

Post a Comment