[英]Asp.NET Mvc 4 Routing
我正在MVC 4中创建博客,并尝试建立路由。
这是现在的样子:
/About/Index
但我希望它看起来像:
/About/Firstname-Lastname
名字和姓氏始终相同; 它不应该是动态的。 这是我到目前为止所拥有的。 我知道这是因为它需要知道显示什么视图。 那么有没有办法说/ About / Firstname-Lastname然后显示Index?
routes.MapRoute(
name: "About",
url: "{controller}/{name}/",
defaults:
new
{
controler = "About",
action = UrlParameter.Optional,
name = "firstname-Lastname"
}
);
这应该可以解决问题
routes.MapRoute(
name: "About",
url: "About/Anne-Refsgaard/",
defaults:
new
{
controler = "About",
action = "Index",
}
);
需要在标准路由之前添加此路由
routes.MapRoute(
name: "FirstnameLastname",
url: "about/Andre-Calil",
defaults: new { controller = "About", action = "Index" }
);
请记住,路线的顺序很重要。 将使用接受请求的第一条路线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.