Asp.net mvc 2 ASP.NET Mvc-可空参数和逗号作为分隔符

Asp.net mvc 2 ASP.NET Mvc-可空参数和逗号作为分隔符,asp.net-mvc-2,routing,asp.net-mvc-routing,Asp.net Mvc 2,Routing,Asp.net Mvc Routing,我应该如何在我的global.asax中定义路由,以便能够使用可为空的参数和coma作为分隔符 我正在尝试为我的搜索用户页面实现路由规则,如 "{Controller}/{Action},{name},{page},{status}" 来自Global.asax的完整条目: routes.MapRoute( "Search", "{controller}/{action},{name},{page},{status}", new

我应该如何在我的global.asax中定义路由,以便能够使用可为空的参数和coma作为分隔符

我正在尝试为我的搜索用户页面实现路由规则,如

"{Controller}/{Action},{name},{page},{status}"
来自Global.asax的完整条目:

    routes.MapRoute(
        "Search",
        "{controller}/{action},{name},{page},{status}",
            new { controller = "User", action = "Find", 
                name = UrlParameter.Optional,
                page = UrlParameter.Optional,
                status = UrlParameter.Optional  } 
    );
当我输入所有参数时,上面定义的例程工作正常,但当某些参数等于null时,路由失败(例如“user/find,,,,,”)


根据以下评论-处理请求的行动方法的信号:

public ActionResult Find(string userName, int? page, int? status)
{
    // [...] some actions to handle the request

}

一开始我用VS调试器测试路由,现在我使用上描述的路由调试器。该工具确认-使用空值的路由没有得到正确处理(或者我做错了什么;)

据我所知.Net路由不允许您这样做多个可为空的参数。多个参数只有在缺少从结尾向后的工作并且缺少分隔符的情况下才有效,这样您就可以获得匹配项

user/find,bob,2,live user/find,bob,2 user/find,bob user/find 到


控制器操作的定义是什么?它是否允许为空值?如果使用斜杠,它是否有效?你可能想在这里读一些讨论,谢谢你的回复。我以为这不可能直接实现。我知道我可以从查询字符串中获取参数值,但我的客户要求是传递如上所示的数据。我发现了一些相似的东西,但与你的版本相比,我的方式是丑陋的。又是Thanx;)
public ActionResult Find(string name, int page, string status){
    //Do stuff here
    return View(result);
}
public ActionResult Find(string parameters){
    string name;
    int? page;
    string status;
    //split parameters and parse into variables
    return FindAction(name, page, status);
}

[NonAction]
public ActionResult FindAction(string parameters){
    //Do what you did in your previous Find action
    return View(results);
}