When to use a routing rule vs query string parameters with asp.net mvc

梦想与她 提交于 2019-12-05 05:37:33
amurra

I would recommend keeping your URL's as clean as possible and to try and use routes whenever possible. You should try and make RESTful URI's that will convey information to the user. For example:

www.yourdomain.com/Products/Sports/Clothing

is a lot cleaner than

www.yourdomain.com/Products?Department=Sports&SubDepartment=Clothing 

If you use a ton of query strings then it won't be a clean URI and less information is conveyed to the user.

With that said, our team does use query strings for ajax type requests using jquery. This is because these URI's are in our markup and won't be seen in the browser window. This has helped keep our global.asax a little smaller since it won't get polluted with a ton of routes.

At my project we only use querystrings for optional values. Thats mostly filtering, sorting and paging lists. Optional values are difficult to handle in a route.

Its much harder to maintain a querystring in the URL. They are not rendered when using ActionLink and other routing aware helpers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!