[英]URL Routing Not Working in ASP .Net MVC2
我正在使用ASP.Net MVC2应用程序。 在那我使用了URL路由
将网址获取为
https://localhost/StudentDetail/SortField
我在Global.asax中编写了以下代码
routes.MapRoute(
"StudentDetail", // Route name
"StudentDetail/{SortField}", // URL with parameters
new { controller = "UDashboard", action = "UAboutMeStudentDetails",
SortField = "Major" }
);
在我看来,链接如下
<a href="/StudentDetail?SortField='Major'" >Students</a>
但这是行不通的。 我的网址是
https://localhost/StudentDetail?SortField='Major'
谁能帮我获得所需的网址吗?
我希望网址为
https://localhost/StudentDetail/SortField
在此先感谢,Prashant
我认为您对路由的工作方式有不正确的想法。 您的路线:
routes.MapRoute(
"StudentDetail", // Route name
"StudentDetail/{SortField}", // URL with parameters
new { controller = "UDashboard", action = "UAboutMeStudentDetails",
SortField = "Major" }
);
将采用SortFeild参数(主要,Gpa等),并将{SortField}替换为该值。 因此,使用以下操作链接:
@Html.ActionLink("Student Details", "UAboutMeStudentDetails", new {controller="UDashboard", SortField = "Major})
将产生以下HTML
<a href="/StudentDetail/Major">Student Details</a>
请注意,SortField的值已替换路由中的{SortField}参数。 您将永远不会获得一个看起来像您所请求的URL,因为您将如何获得操作的SortField值?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.