user998405
user998405

Reputation: 1339

Asp.net 5 mvc 6 get query string to view

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

Upvotes: 14

Views: 16541

Answers (2)

user998405
user998405

Reputation: 1339

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

Upvotes: 1

digiliooo
digiliooo

Reputation: 841

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

Upvotes: 45

Related Questions