0

我打算在 ASP .NET MVC3 中注册如下路由:

routes.MapRoute(
            "SearchRoute", // Route name
            "Report/Search/{code}/{quarter}/{year}/{receivedBegin}/{receivedEnd}/{transactionBegin}/{transactionEnd}/{page}", // URL with parameters
            new {
                controller = "Report",
                action = "Search",
                page = UrlParameter.Optional } // Parameter defaults
        );

该路由将链接到名为 Report 的控制器中的此函数:

public ActionResult Search(string code, int? quarter, int? year, 
            DateTime? receivedBegin, DateTime? receivedEnd,
            DateTime? transactionBegin, DateTime? transactionEnd, int? page=1)

我预计 Html.ActionLink 生成的指向该函数的链接将生成如下:Report/Search/10/2/2012/04-30-2012/04-01-2012/04-30-2012

当我使用 Html.ActionLink 生成链接时,生成的链接如下:

Report/Search?code=100&quarter=2&year=2012&receivedBegin=04-01-2012&receivedEnd=04-30-2012&transactionBegin=04-01-2012&transactionEnd=04-30-2012

我应该怎么做才能产生预期的结果?谢谢你。

更新

这是我用来创建链接的代码:

@Html.ActionLink("First", "Search", new { 
    code = currentCode, 
    quarter = currentQuarter, 
    year = currentYear, 
    receivedBegin = currentReceivedBegin, 
    receivedEnd = currentReceivedEnd, 
    transactionBegin = currentTransactionBegin, 
    transactionEnd = currentTransactionEnd }, null).
4

1 回答 1

2

不,这不是我注册的第一条路线。我必须先注册吗?

是的。RegisterRoutes您的方法中的规则global.asax应该按照具体的顺序从上到下,因此这条路线绝对应该在(或至少接近)顶部。

默认路由应该始终是最后一个。

于 2012-04-27T08:09:43.990 回答