Asp.net mvc 的 URL 路由
我正在使用 ASP.Net MVC2 C#,我有一个如下所示的 URL:
http://localhost:2107/News/NewsHome/NewsDetails/Celebrate_the_dedicate_of_healthcare_quality_professionals_during_National_Healthcare_Quality_Week
这里 News 是 Area,NewsHome 是控制器,但我想要URL 看起来像这样
http://localhost:2107/NewsDetails/Celebrate_the_dedicate_of_healthcare_quality_professionals_during_National_Healthcare_Quality_Week
是否有任何选项可以从 URL 获取区域和控制器名称?
I am using ASP.Net MVC2 C# and I have a URL like below:
http://localhost:2107/News/NewsHome/NewsDetails/Celebrate_the_dedication_of_healthcare_quality_professionals_during_National_Healthcare_Quality_Week
Here News is Area and NewsHome is the controller but I want the URL to look like this
http://localhost:2107/NewsDetails/Celebrate_the_dedication_of_healthcare_quality_professionals_during_National_Healthcare_Quality_Week
Is there any option to get area and controller name from the URL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以定义类似
"NewsDetails/{name}
的路由,并在defaults
参数中指定区域、控制器和操作(例如,new { area = "News ",controller = "NewsHome", action = "NewsDetails" }
)。如果你将路由定义为
"{action}/{name}"
,它会吞掉你所有的其他路线也是如此。You can define a route like
"NewsDetails/{name}
and specify the area, controller and action in thedefaults
parameter (eg,new { area = "News", controller = "NewsHome", action = "NewsDetails" }
).If you define the route as
"{action}/{name}"
, it will swallow up all of your other routes too.定义新路线
Define a new Route