[英]URL Routing Not Working in ASP .Net MVC2
I am working ASP.Net MVC2 application. 我正在使用ASP.Net MVC2应用程序。 In that i have used URL Routing 在那我使用了URL路由
To get URL as 将网址获取为
https://localhost/StudentDetail/SortField
I have written below code in Global.asax 我在Global.asax中编写了以下代码
routes.MapRoute(
"StudentDetail", // Route name
"StudentDetail/{SortField}", // URL with parameters
new { controller = "UDashboard", action = "UAboutMeStudentDetails",
SortField = "Major" }
);
And In my view link is as below 在我看来,链接如下
<a href="/StudentDetail?SortField='Major'" >Students</a>
But it is not working. 但这是行不通的。 and my URL is 我的网址是
https://localhost/StudentDetail?SortField='Major'
Can anyone please help me to get the required URL..? 谁能帮我获得所需的网址吗?
I want URL as 我希望网址为
https://localhost/StudentDetail/SortField
Thanks In Advance, Prashant 在此先感谢,Prashant
I think you have an incorrect thought on how routing works. 我认为您对路由的工作方式有不正确的想法。 Your route: 您的路线:
routes.MapRoute(
"StudentDetail", // Route name
"StudentDetail/{SortField}", // URL with parameters
new { controller = "UDashboard", action = "UAboutMeStudentDetails",
SortField = "Major" }
);
Will take the SortFeild parameter (Major, Gpa, etc), and replace {SortField} with that value. 将采用SortFeild参数(主要,Gpa等),并将{SortField}替换为该值。 So, using the following actionlink: 因此,使用以下操作链接:
@Html.ActionLink("Student Details", "UAboutMeStudentDetails", new {controller="UDashboard", SortField = "Major})
would produce the following HTML 将产生以下HTML
<a href="/StudentDetail/Major">Student Details</a>
Note that the value of SortField has replaced the {SortField} parameter in your route. 请注意,SortField的值已替换路由中的{SortField}参数。 You would never get a URL looking like what you are requesting as how would you get the value of SortField to the action? 您将永远不会获得一个看起来像您所请求的URL,因为您将如何获得操作的SortField值?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.