14

I have been googling for a few hours. But still not able to get the answer. I need to get a query string parameter in a razor view.

Here is my code:

              if @(Request.Query["value"]=="P"){

                    <a href="@Url.Action("Index", "Staff",new { status = "A"})"><strong>Active (@ViewData["activeCount"]) </strong></a> &nbsp;
                    <a href="@Url.Action("Index", "Staff",new { status = "I" })">In-Active (@ViewData["inActiveCount"])</a>&nbsp;
                    <a href="@Url.Action("Index", "Staff",new { status = "D" })">Delete (@ViewData["deleteCount"])</a>&nbsp;
               }else{
                    <a href="@Url.Action("Index", "Staff",new { status = "A"})">Active (@ViewData["activeCount"])</a> &nbsp;
                    <a href="@Url.Action("Index", "Staff",new { status = "I" })"><strong>In-Active (@ViewData["inActiveCount"])<strong></a>&nbsp;
                    <a href="@Url.Action("Index", "Staff",new { status = "D" })">Delete (@ViewData["deleteCount"])</a>&nbsp;

               }

But i get the error "The name 'Request' does not exist in the current context"

The screenshot enter image description here Anyone got solution? Thanks

2
  • Have you tried using Context.Request.Query ["value"] rather than just Request.Query ["value"]? Commented Jan 28, 2016 at 9:02
  • Sure thing, I'm glad it worked for you Commented Jan 28, 2016 at 17:13

2 Answers 2

45

Use Context.Request.Query["value"] rather than Request.Query["value"]

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

1 Comment

Surprised how long it took to find this answer
1

Yes you finally can. The answer is Context.Request.Query ["value"]

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.