路线不匹配

时间:2013-03-08 10:28:14

标签: asp.net-mvc-4

The App

如果指定了CoId,我有一个视图,其中包含给定公司的客户列表,否则,所有已注册的客户端都会出现在列表中。 HanlderId只代表谁在处理客户。该列表被分页(因此是页面参数)并进行排序,因此后面的代码中的sortField和sortDir。一切正常,除了路线。所以......

设置

我有一个区域注册文件,其路径如下:

context.MapRoute(
                "Companies_Clients",
                "Companies/Clients/Page/{page}/{sortField}/{sortDir}/{HandlerId}/{CoId}",
                new
                {
                    controller = "MyController",
                    action = "Index", 
                    CoId = -1,
                    HandlerId = -1, 
                    page = 1, 
                    sortField = "ClaimId",
                    sortDir = "ASC", 
                    AccidentDate = UrlParameter.Optional,
                    DateOfBirth = UrlParameter.Optional,
                    ClientSurname = UrlParameter.Optional,
                    InvoiceNumber = UrlParameter.Optional
                }
            );

默认为UrlParameter.Optional的参数是搜索参数(也可以搜索列表)。

我在MyController中有一个定义如下的动作:

public virtual ActionResult Index(
    Nullable<int> FeId = -1, 
    Nullable<DateTime> AccidentDate = null, 
    Nullable<DateTime> DateOfBirth = null,
    string ClientSurname = null,
    Nullable<int> InvoiceNumber = null, 
    int page = 1, string sortField = "ClaimId", string sortDir = "DESC", int SolicitorId = -1)
{
    var model = service.BuildModel(FeId, AccidentDate, DateOfBirth, ClientSurname, InvoiceNumber, page, sortField, sortDir, SolId);
    return View("Index", model);
}

我希望所有对Index的调用都与我的“Companies_Clients”路由匹配。

问题

来自@ Html.ActionLink助手调用的结果URL(请参阅下一个代码块)与“Companies_Clients”路由不匹配。

//This creates a link with a url that matches the default route (the usual one)
@Html.ActionLink("Sort by Client Name", MVC.MyArea.MyController.Index(feId, accidentDate, dateOfBirth, clientSurname, invoiceNumber, currentPage, "ClientSurname", "DESC"))

匹配路由的是什么,我的mvcSiteMap节点:

<mvcSiteMapNode title="Clients" area="Companies" controller="MyController" action="Index" key="clients">

即,这个mvcsitemap节点生成的路由是:

/Companies/Clients/Page

问题

琐碎的问题是:

我做错了什么?为什么Html.ActionLink调用不匹配路由?

另一个问题是:

为什么默认参数不会出现在mvcsitemapnode生成的路由中?

0 个答案:

没有答案