我正在建立一个博客,我想建立一个基于company.com/blog/category_name的网址
到目前为止,我只能使用以下路线建立company.com/blog/category/category_name
routes.MapRoute(
"Blog Category",
"Blog/Category/{category}",
new { controller = "Blog", action = "Category" }
);
Action Link的构建方式如下:
@Html.ActionLink(category.Name, "Category", "Blog", new { category = category.UrlSlug }, new { title = String.Format("See all posts in {0}", category.Name) });
如何更改路线以便我可以实现第一个版本?
答案 0 :(得分:0)
你需要这样的东西:
routes.MapRoute(
"Blog Category",
"{controller}/{id}",
new { controller = "Blog",
action = "Category",
id = UrlParameter.Optional
}
);