Home > DeveloperSection > Forums > How to maproute and querystings in mvc?
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    October-30-2014 12:30 AM

 ASP.NET MVC ASP.NET MVC  Mvc4 
Ratings:


 1 Reply(s)
 582  View(s)
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.



Hugh Jackman
Hugh Jackman

Total Post:52

Points:366
Posted on    October-30-2014 12:34 AM

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!


Don't want to miss updates? Please click the below button!

Follow MindStick