Coding

Published on September 25th, 2016 | by Guest

0

Parameterized URL Routing in Asp.Net MVC Application

Experts working in asp.net development company India explain the Routing and its use in mvc app development. In this article, they will explain the multiple level of routing based on the data structure captured.

Routing is one of the key feature in MVC. But URL routing is the most multifaceted topic in Asp.Net. But MVC introduced routing Framework which will simplify the developer’s coding and logics.

As stated above URL routing in the Asp.net needs complex logic and needs to write more coding. In MVC default routing is available which is very simple and it will be used for standard URL formats, for our real business needs, we need to customize the existing routing logics.

This article will explain about the multiple level of routing based on the structure of data captured.

I am taking example of capturing the geographical data in a MVC Razor application.

Create the Table with following data

S.NOCountryStateCity
1IndiaTamilNaduChennai
2IndiaTamilNaduTrichy
3IndiaTamilNaduMadurai
4IndiakarnatakaBengaluru

 

Create the Data Model using the above table.

Create the Controller for consume those data and transfer to the views.

Below three Actions will be created to show the three different routing,

  • Action Index is the home page which will display without any filter.

  • Action State will be used to display the records based on the state filler

  • Action City will be used to display the records with both State and City filters.

Create Views for the respective controllers.

Coding samples for View: Cities

Coding samples for View:  States

Default routing is defined in RouteConfig.cs under App_Start folder. On top of it I have created the customized routing logic for State and Cities controllers.

ControllersRouting DesignUrl Example
CityLocalhost/{GeoData}/{StateName}/Cities/{CityName}http://localhost:55946/GeoData/TamilNadu/Cities/Madurai

In this URL http://localhost:55946/GeoData/TamilNadu/Cities/Chennai

State name “TamilNadu” and City Name “Chennai”. Based the query, data will be displayed as like below

image00

ControllersRouting DesignUrl Example
StateLocalhost/{GeoData}/{StateName}http://localhost:55946/GeoData/TamilNadu

In this URL http://localhost:55946/GeoData/TamilNadu

“Tamilnadu” is the state name, it will pass to the respective controller and display the filtered data by use of linq query.

image01

Hope you understood the instances shared by experts who work for asp.net development company India.

If you need to discuss anything related to URL routing or want info about mvc development services, contact experts today

Conclusion

This article have explained how we can customize the existing routing Configuration for our business need in Asp.Net MVC application in simplest way.

URL routing can be achieved in many ways like Regex routing, Angular JS Url routing and using IRouteConstraint Interface.

In this article I am concentrating on the customization of Base route framework in MVC.

Hope this article is very clear and easy to follow. This has been created based on my practical assignment done for one of my customer requirement.

Like this post? Share with your friends.
Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Share on Google+
Google+
0Share on LinkedIn
Linkedin
Share on Reddit
Reddit
0Share on Tumblr
Tumblr
0Share on VK
VK
Email this to someone
email

Tags: , , , , , ,


About the Author

Guest

Contribution of guest authors towards Techno FAQ blog



Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top ↑