Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 223
user998405 Avatar asked Jan 28 '16 08:01

user998405


2 Answers

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

like image 88
digiliooo Avatar answered Oct 30 '22 12:10

digiliooo


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

like image 31
user998405 Avatar answered Oct 30 '22 12:10

user998405