Accessing data from Querystring to Action method

Manideepgoud
Posted by Manideepgoud under ASP.NET MVC category on | Points: 40 | Views : 567
We can access data from querystring to action method using two ways
1.using parameter action method
2.using Request.QueryString.

Actionmethod
public ActionResult Details(int id)
{
ViewBag.Id=id;
ViewBag.name=Request.QueryString["name"]
return View();
}

In the above code we accessed id QueryString with action method and name QueryString with Request.QueryString
View code
<h2>Details</h2>
@ViewBag.Id
<p>@Request.QueryString["id"]</p>
@ViewBag.Name
<p>@Request.QueryString["name"]</p>

In the view code QueryString will be directly accessed using
@Request.QueryString

Comments or Responses

Login to post response