映射路由MVC3

时间:2012-12-15 10:48:37

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

也许我的问题很容易回应,但我是MVC3的新手。

我在MVC3 Web项目中有这些可能的路径:

  • /品牌/ brandID
  • /品牌/ {动作} / {参数}

其中brands是我的控制器,brandID是接收我的Index操作的特定参数。此外,我的品牌控制器有更多的操作,我需要在Global.asax中定义正确的地图路线,以使其工作。

1 个答案:

答案 0 :(得分:0)

Custom Routing中有一个示例(根据您的情况进行了修改)。

的Global.asax:

routes.MapRoute(
    "BrandDetails",
    "Brands/{brandID}",
    new { controller = "Brands", action = "Details" },
    new { brandID = @"\d+" }
);

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

BrandsController:

public ActionResult Index()
{
    return View();
}

public ActionResult Details(int brandID)
{
    return this.View(brandID);
}
相关问题