Asp.net mvc 特定控制器的两个可选参数的路由

Asp.net mvc 特定控制器的两个可选参数的路由,asp.net-mvc,asp.net-mvc-routing,Asp.net Mvc,Asp.net Mvc Routing,在特定的控制器中,我有接受两个参数的操作。有些操作是get,有些操作是在post上执行的 [HttpGet] public ActionResult CodeRead([DataSourceRequest] DataSourceRequest request, string group, string system) [HttpPost] public ActionResult CodeCreate([DataSourceRequest] DataSourceRequest request,

在特定的控制器中,我有接受两个参数的操作。有些操作是
get
,有些操作是在
post
上执行的

[HttpGet]
public ActionResult CodeRead([DataSourceRequest] DataSourceRequest request, string group, string system)

[HttpPost]
public ActionResult CodeCreate([DataSourceRequest] DataSourceRequest request, ZCodes code, string group, string system)
查询字符串类似于:

http://localhost:3086/xxx/CodeRead/01/00
我已经定义了以下路由,但我总是得到一个空的
<代码>系统和
请求
都可以

    routes.MapRoute("Parameters", "xxx/{action}/{group}/{system}",
        new { controller = "xxx", action = "CodeRead", group = UrlParameter.Optional, system = UrlParameter.Optional });

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}

我也交换了路线和地点,但没用

将参数置于默认值之上

routes.MapRoute("Parameters", "xxx/{action}/{group}/{system}",
        new { controller = "xxx", action = "CodeRead", group = UrlParameter.Optional, system = UrlParameter.Optional });
}   

routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
一模一样。路由很好,模型包含一个名为
group
的字段,我只需要将该参数重命名为其他参数

[HttpGet]
public ActionResult CodeRead([DataSourceRequest] DataSourceRequest request, string somethingElse, string system)

[HttpPost]
public ActionResult CodeCreate([DataSourceRequest] DataSourceRequest request, ZCodes model, string somethingElse, string system)

您的“参数”路由需要在“默认”路由之前。你能澄清一下你所说的“我总是得到一个空的组,系统和请求都是好的”是什么意思吗-哪些是空的,哪些是好的。只是组是空的。我试过交换路线的位置,但没有成功。您的“参数”路线必须是第一个。但是你展示的
ActionResult
方法是一篇文章,当你使用
。/xxx/CodeRead/01/00
时,你所指的GET方法的签名是什么?我已经将该路径放在了第一位,它没有改变任何事情。这个
ActionResult
实际上是一个
get
one,但是我还要添加一个
post
one。我还有一些其他的,我不知道怎么了。为什么在GET方法中有参数
DataSourceRequest
?您有3个参数,但
。/xxx/CodeRead/01/00
仅通过2个参数