There are at least two ways to retrieve querystring data into the Controller action method.
BROWSER ADDRESS BAR URL
ACTION METHOD CODE
public ActionResult Details(int id) { ViewBag.Id = id; ViewBag.Name = Request.QueryString["name"]; return View(); }
In the above code, we are accessing the “id” querystring by the action method parameter and “name” querystring by using Request.QueryString object.
VIEW CODE
<h2>Details</h2> The querystring value is <strong>@ViewBag.Id</strong> <p> @Request.QueryString["id"] </p> <p>@ViewBag.Name</p> @Request.QueryString["name"]
In the View, querystring can be accessed directly using @Request.QueryString
also.