2

I have an asp.net mvc 5 project. Inside a view I want to pass a parameter from the request's query string to an action. Here's what i did:

<a href="@Html.Action("GetData", "TestController", Request.QueryString["param"])"> Click here</a>

But this doesn't pass the querystring param. Any ideas? Thanks

3
  • 2
    @Html.Action("GetData", "TestController", new { param = Request.QueryString["param"] }) Commented Dec 8, 2014 at 16:09
  • possible duplicate of Specify QueryString in Html.Action Commented Dec 8, 2014 at 16:10
  • 2
    You could use <a href="@Url.Action("GetData", "TestController", new{ parameter = Request.QueryString["parameter"]})">Click here</a> Commented Dec 8, 2014 at 16:24

1 Answer 1

3

You should be able to use an ActionLink helper

@Html.ActionLink("GetData", "TestController", new { param = Request.QueryString["param"] })
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.