1

我在面向公众的网页的控制器中有以下设置

Company -> About -> Partners(我希望以Company/About/Partners的身份访问) 操作方法

public about(string category)
{
  ViewBag.Category = category;
  return View();
}

链接的生成如下完成,这给了我错误的 URL

@Html.ActionLink("Partners & Investors", "About", "Company",new { Category = "Partners" },null)

错误的网址

Company/About?Category=Partners%20and%20Investors

所以问题是如何生成我想要的正确网址。我该怎么办 ?

4

1 回答 1

2

automatically当您创建新route的并将其放在正确的位置时,将生成 URL 。

添加

像这样的东西:

routes.MapRoute(
    "Category",
    "Company/About/{category}",
    new { controller = "Company", action = "About", category = "default" }
);

// default
routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

另请查看此链接:高级路由

于 2012-09-28T07:41:43.523 回答