tags:

views:

438

answers:

2

Hi,

I have a call that looks like this:

<%= Html.RouteLink(item.displayName, "DisplayCategory", new { category = Html.Encode(item.displayName), subcat = item.searchName }) %>

and I'm getting html that looks like this:

http://localhost:1485/Home/ShowCategory/Electronics%20&amp;%20Photography?subcat=electronics-photo

Why does the URL end with "?subcat=electronics-photo" rather than "/electronics-photo" ? Is it somehow related to the route definition?

   routes.MapRoute(
        "DisplayCategory",
        "Home/ShowCategory/{category}/{tags}",
        new { controller = "Home", action = "ShowCategory", category = "", tags = "" }
    );

Any clues would be appreciated!

A: 

I'm just taking a stab but it looks like you're using the MVC framework.

In it every controller has an action, in this case ShowCategory, and by default they take a query string, in this case category. MVC purposefully abstracts the folder sturcture. I believe a MVC app will always have a URL of this type and depth domain.ext/Controller/Action?queryString.

I think the question may be whether or not the subcat is set to properly. A little more info/code might be hopeful.

Also sorry for not addressing the routing portion of your question.

Thanks for the reply. Yes, I am using MVC...what I'm confused about is why it creates ?queryString rather than just adding another '/' and making /queryString.
MVC uses a query string to pass parameters to the action. The '/' is only used to access sub folders except in MVC you only ever have the controller and action folders.
+1  A: 

MVC routing tacks on a query string if it can't match one of the parameters in the route definition. Try adding subcat to your route:

routes.MapRoute(
        "DisplayCategory",
        "Home/ShowCategory/{category}/{tags}/{subcat}",
        new { controller = "Home", action = "ShowCategory", category = "", tags = "", subcat = "" }
    );
Jason