使用ASP MVC,我有以下Action链接,
<a href="@Url.Action("Page", "Content", new { publicationId = publication.PublicationId })">@publication.Title</a>
用于控制器操作
public ActionResult Page(int publicationId)
哪个有效,但URL看起来像这个
Content/Page?publicationId=129
我希望它看起来像
内容/页/ 129
无论如何都要做出改变吗?
答案 0 :(得分:1)
您需要为publicationId
控制器定义使用Content
参数的路线
在App_Start\RouteConfig.cs
路线上方添加Default
:
routes.MapRoute(
name: "ContentPage",
url: "Content/{action}/{publicationId}",
defaults: new { controller = "Content", action = "Page", publicationId = UrlParameter.Optional }
);
如果您希望它仅针对Page
操作:
routes.MapRoute(
name: "ContentPage",
url: "Content/Page/{publicationId}",
defaults: new { controller = "Content", action = "Page", publicationId = UrlParameter.Optional }
);