0

I am working ASP.Net MVC2 application. In that i have used URL Routing

To get URL as

    https://localhost/StudentDetail/SortField

I have written below code in 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

1
  • 1
    <a href="/StudentDetail/Major" >Students</a> should work. Commented Aug 29, 2013 at 13:55

1 Answer 1

1

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. So, using the following actionlink:

@Html.ActionLink("Student Details", "UAboutMeStudentDetails", new {controller="UDashboard", SortField = "Major}) 

would produce the following HTML

<a href="/StudentDetail/Major">Student Details</a>

Note that the value of SortField has replaced the {SortField} parameter in your route. You would never get a URL looking like what you are requesting as how would you get the value of SortField to the action?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.