我在 global.asax 中有这些路由
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}/{Name}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional },
namespaces: new[] {"MVCTemplateProject.Controllers"}
);
routes.MapRoute(
name: "Post",
url: "{controller}/{action}/{id}/{Title}",
defaults: new {controller = "Post", action = "Index", id = UrlParameter.Optional, Title = UrlParameter.Optional},
namespaces: new[] {"MVCTemplateProject.Controllers"}
);
routes.MapRoute(
name: "GetPostByCategoryName",
url: "{controller}/{action}/{CategoryName}",
defaults:
new {controller = "Post", action = "Index", id = UrlParameter.Optional, CategoryName = UrlParameter.Optional},
namespaces: new[] {"MVCTemplateProject.Controllers"}
);
如果我单击该行并重定向到具有相同地址的相同链接的页面,则 我有一个与此 href http://mysite.com/Post/GetPostsByTagId/3/a的链接,因此我的链接具有此地址http://mysite .com/Post/GetPostsByTagId/3/a/2/asdasd 并引发错误这是我的链接语法
<a href="@Url.Action(MVC.Post.ActionNames.GetPostsByCategoryId,MVC.Post.Name)\@category.Id\@category.Name.ToSeoUrl()">@category.Name</a>