希望在阅读 MVC 路由后得到一些帮助,但自己没有想出答案。
我注册了以下路线:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
null,
"YourFeedback/Article/{resourceId}",
new { controller = "YourFeedback", action = "Index", contentTypeId = new Guid(ConfigurationManager.AppSettings["ArticleLibraryId"]) });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
我在 aspx 视图中有以下 ActionLink:
<%=Html.ActionLink("Your Feedback", "Article", "YourFeedback", new
{
resourceId = Model.ContentId.ResourceId
}, new { @class = "yourFeedback" })%>
我对 MVC 路由的理解是,这将呈现一个带有“/YourFeedback/Article/101”href 的锚链接,其中 101 来自 Model.ContentId.ResourceId。
然而,锚链接 href 呈现为“YourFeedback/Article/resourceId=101”。
有什么想法我哪里出错了吗?
提前致谢。