0

I have an MVC website , on product page I have link for every product to view product in detail. My controller is :

 public ActionResult ViewProduct(string id, string title)
        {
}

Route Config:

routes.MapRoute(
                name: "viewProduct",
                url: "ShopWindow/Product/{title}/{id}",
                defaults: new { controller = "ShopWindow", action = "ViewProduct" , title  = UrlParameter.Optional, id = UrlParameter.Optional }
                );

when user click on any product link, in the browser url shows like :

   http://localhost:53298/ShopWindow/Product/ADAM-LEVINE-100ML/59fc90e63bf0de22006c332e

I was wondering is there a way to remove/hide the product id from the URL like:

   http://localhost:53298/ShopWindow/Product/ADAM-LEVINE-100ML/

Thanks

Fahad
  • 173
  • 1
  • 12
  • Possible duplicate of [Modify the URL without reloading the page](https://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page) – Adisesha Nov 24 '17 at 13:47
  • Looks like you need to pass the 'id' to the server. If your intention is to hide the id from user, you can't do it. User can still see the request params using developer tools. – Adisesha Nov 24 '17 at 13:49
  • Yes I agree the user can view in developer tool. I just wanted the URL to appear clean in browser. So I thought there might be a way to achieve this. – Fahad Nov 24 '17 at 14:10
  • Possible duplicate of [Multiple levels in MVC custom routing](https://stackoverflow.com/questions/31934144/multiple-levels-in-mvc-custom-routing). The ID can be hidden if you keep track of it in the routing on the server side. – NightOwl888 Nov 25 '17 at 12:43

0 Answers0