1

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

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

  • /品牌/品牌ID
  • /brands/{action}/{参数}

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

4

1 回答 1

0

自定义路由中有一个示例(针对您的情况进行了修改)。

全球.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 }
);

品牌控制器:

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

public ActionResult Details(int brandID)
{
    return this.View(brandID);
}
于 2012-12-15T11:06:39.660 回答