0

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?

Shay Erlichmen
  • 31,691
  • 7
  • 68
  • 87
iasksillyquestions
  • 5,558
  • 12
  • 53
  • 75

2 Answers2

3

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!

iasksillyquestions
  • 5,558
  • 12
  • 53
  • 75
  • 2
    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 Dec 31 '08 at 23:51
2

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

Strelok
  • 50,229
  • 9
  • 102
  • 115