How to maproute and querystings in mvc?

Total Post:154

Points:1086
 1170  View(s)
Ratings:
Rate this:
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.

  1. Post:51

    Points:359
    Re: How to maproute and querystings in mvc?

    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!

      Modified On Apr-06-2018 01:46:37 AM

Answer