views:

1042

answers:

2

I have two routes:

routes.MapRoute(
            "FetchVenue",                                     
            "venue/fetchlike/{q}",                                     
            new { controller = "venue", action = "fetchlike" }      
        );

        routes.MapRoute(
            "venue",                                         
            "venue/{venueId}",                                 
            new { controller = "Venue", action = "Index" }   
);

The url /venue/fetchlike/test is passed to the correct controller The url /venue/fetchlike/?q=test is however passed to the index action.

I want to be able to pass data as a querystring.

What am I doing wrong?

+1  A: 

Just off the top of my head, shouldn't your URL look like /venue/fetchlike?q=test, instead of /venue/fetchlike/?q=test

Strelok
/venue/fetchlike?q=test will still map to the named route "venue"Stumped :(
ListenToRick
The above comment is utter rubbish!!
ListenToRick
+2  A: 

Actually the issue was that the route:

 routes.MapRoute( "FetchVenue", "venue/fetchlike/{q}",  new { controller = "venue", action = "fetchlike" });

should actually have been:

 routes.MapRoute( "FetchVenue", "venue/fetchlike",  new { controller = "venue", action = "fetchlike" });

Meaning that the url would have been:

/venue/fetchlike?q=test

as suggested above by strelokstrelok.

So, in the case of querysting parameters, you DONT define them in the route!

ListenToRick
Exactly! Routes should not have query string parameters in them. For the purposes of route matching, query string is ignored. When generating urls, we append extra supplied parameters to the query string.
Haacked