HOW TO MAPROUTE AND QUERYSTINGS IN MVC?

Manoj Bhatt

Total Post:154

Points:1086
Posted by  Manoj Bhatt
 874  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. Hugh Jackman

    Post:52

    Points:366
    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!

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!