gpt4 book ai didi

asp.net-mvc - map 路由asp.net mvc

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:33:08 25 4
gpt4 key购买 nike

我正在努力使我的 url seo 友好。我需要用这种结构制作 url

www.domainname.com/article123.

还有这条路线

routes.MapRoute(
"articlename", // Route name
"aaaa/{articleID}", // URL with parameters
new {action="DetailsByName",controller="Article"},
new string[] { "bssnew.Controllers" } // Parameter defaults);

这是行不通的。我的路线链接看起来像这样

 @Html.RouteLink("aaa ","articlename", new {articleID="CentralPark",},new { @class = "item-link" })

但是当我在路由中添加 Controller 和 Action 时它起作用了

 routes.MapRoute(
"articlename", // Route name
"aaaa/{controller}/{action}/{articleID}", // URL with parameters
new {action="DetailsByName",controller="Article"},
new string[] { "bssnew.Controllers" } // Parameter defaults);

最佳答案

如果你只需要一个 ID 特定的路由,下面的方法应该可行

routes.MapRoute(
"articlename", // Route name
"{articleID}", // URL with parameters
new { action="DetailsByName",controller="Article" }, // parameter defaults
new[] { "bssnew.Controllers" } // controller namespaces
);

假设你有一个看起来像这样的 Controller

namespace bssnew.Controllers
{
public class Article : Controller
{
public ActionResult DetailsByName(string articleID)
{
...
}
}
}

关于asp.net-mvc - map 路由asp.net mvc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17388972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com