Link to home
Start Free TrialLog in
Avatar of pzozulka
pzozulka

asked on

How to pass query string parameter with ActionLink in MVC

Below is my Razor syntax. I am trying to pass the s.StudentId via query string. The first <div> tag works fine, and I wanted to practice a little bit with ActionLink.

When the page loads in the browser, the links generated are:

1st div: http://localhost:57707/Students/Edit/?_studentId=1
2nd div: http://localhost:57707/Students/Edit?Length=8

What am I doing wrong inside the ActionLink, and why is it defaulting to Length=8?

@foreach (Student s in studentList)
{
    <div>@s.Email <a href="/Students/Edit/?_studentId=@s.StudentId">Edit</a></div> // Using query string to pass params

    <div>@s.Email @Html.ActionLink("Edit", "Edit", "Students", new { _studentId = s.StudentId })</div>}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dustin Hopkins
Dustin Hopkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<div>@s.Email <a href="/Students/Edit/?_studentId=@s.StudentId">Edit</a></div> // Using query string to pass params

Should be

<div>@s.Email <a href="/Students/Edit?_studentId=@s.StudentId">Edit</a></div> // Using query string to pass params

can you post controller method for Edit of student, I think you have a parameter name length over there.