maproute,querystings和mvc

时间:2008-12-17 23:46:33

标签: asp.net-mvc model-view-controller routing query-string maproute

我有两条路线:

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

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

将url / venue / fetchlike / test传递给正确的控制器 然而,url / venue / fetchlike /?q = test将传递给索引操作。

我希望能够将数据作为查询字符串传递。

我做错了什么?

2 个答案:

答案 0 :(得分:3)

实际上问题是路线:

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

实际应该是:

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

这意味着网址应该是:

/地点/ fetchlike Q =测试

如上所述strelokstrelok。

因此,在查询参数的情况下,你不能在路线中定义它们!

答案 1 :(得分:2)

我的网址不应该是/venue/fetchlike?q=test,而不是/venue/fetchlike/?q=test