0

I have a problem in MVC project in url.

In the Route config I have the following code:

routes.MapRoute(
           name: "Test",
           url: "{controller}/{action}/{id}/{selected}/{category}/{engineId}‌​",
           defaults: new { controller = "Product", action = "SubCategories"}
       );

The parameter category contains the name of selected category. In database I have the category with name: "Packet / Set". If in my website I choose this category and in the url will appear this categoryname

SubCategories/92/Bertone-FREECLIMBER-2.0/Packet / Set /33720‌%E2%80%8B.

I got the

 Server Error in '/' Application.
 The resource cannot be found. 

error. If the the category name doesn't contain the "/" character, evrything works fine:

SubCategories/94/Bertone-FREECLIMBER-2.0/Air%20filter/33720%E2%80%8C%E2%80%8B

Could you advise how should I resolve this?

Orsi
  • 545
  • 2
  • 10
  • 27
  • You need to escape the / in route name, refer http://stackoverflow.com/questions/30972578/route-parameter-with-slash-in-url – Anil Mar 28 '17 at 11:16

1 Answers1

0

You need to encode the all slashes in URL as %2F. You can use Javascript encodeURIComponent() function. MVC automatically decodes URL and action parameters so you should be able to get values correctly in your controller without any additional effort. Take a look here for more info: https://www.w3schools.com/jsref/jsref_encodeuricomponent.asp

Ognjen Babic
  • 727
  • 1
  • 4
  • 14