I have a page created on VS13 MVC 5 based on ASP.NET, on my navigator I have my dropdown menu
While I click on Phones link I have URL as: www.sitename.com/phones and it will list all phones which I have on my data base, while I choose a brand (e.g: Samsung) I want my URL will be www.sitename.com/phones/samsung
Simple question I don’t want create a view for each brand or model of phone because there are a lot, I can just use SQL and list them on the same page but how to change my URL depending on my choice ? Is the only way is Attribute Routing?
Appreciate any suggestion.
2
Answers
If you are using JS/jQuery you can use the History.js api. https://github.com/browserstate/history.js/
You can then use
History.pushState(insert parameters here);
. This will not only change the url to your choice but also allow users to go back and forward like usual, it also keeps SEO with web crawlers I think.You can add a Route to your route config
in
RouteConfig.cs
in
product controller