带子视图的Asp.Net MVC路由

时间:2019-02-09 04:36:58

标签: asp.net asp.net-mvc asp.net-mvc-routing

我有一个控制器“ Home”,其中有2个动作,称为“ DeliveryReturn”,还有一个名为“ BasketReturn”的动作,如下所示:

public ActionResult DeliveryReturn(string id)
{
    return View();
}
public ActionResult BasketReturn(string id)
{
    return View();
}
  • “ ... / Home / Return / Delivery / 10”->应该调用DeliveryReturn。
  • “ ... / Home / Return / Basket / 10”->应该调用BasketReturn。

我尝试这样设置路线。虽然我真的迷路了,但似乎根本没有任何意义。

routes.MapRoute(
    name: "Return",
    url: "Home/Return/{type}/{id}",
);

更新

我发现,我可以做这样的事情。但是,这将需要我注册两个路由。我只用一个怎么办?

routes.MapRoute(
    name: "DeliveryReturn",
    url: "Home/Return/Delivery/{id}",
    defaults: new { controller = "Home", action = "DeliveryReturn", id= ""}
);
routes.MapRoute(
    name: "BasketReturn",
    url: "Home/Return/Basket/{id}",
    defaults: new { controller = "Home", action = "BasketReturn", id= ""}
);

0 个答案:

没有答案