Retrieve Data from the Request Object in ASP.NET MVC

Published on April 30, 2013 by admin

Filed under ASP.NET

Last modified April 30, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 4.2 (6 votes)

This article have been viewed 38971 times

In ASP.NET MVC, the Request property defined within the controller can be used to retrieve the data about the request. They can be accessed easily in the controller.

Some of the useful properties within the Request objects includes

  1. Request.QueryString – This is a NameValueCollection which can be used to access variable sent with this request using GET method.
  2. Request.Form – This is a NameValueCollection will can be used access variables sent using POST variables.
  3. Request.Cookies – This is the cookie sent with this request.

Retrieve Data from the Request Object in ASP.NET MVC

Retrieve Data from the Request Object in ASP.NET MVC

Below is a sample code snippet demonstrating how to retrieve data from the request object in ASP.NET MVC.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

namespace UrlsAndRoutes.Controllers


public class CustomerController : Controller


public ActionResult Index()


ViewBag.Controller = "Abundant Code Controller";

string QueryString = Request.QueryString["Name"];

string form1 = Request.Form["Variable1"];

string cookie1 = Request.Cookies["Cookie1"].ToString();

ViewBag.Action = "Index";

return View("ActionName");





  1. Interesting .NET Links – May 1 , 2013 | TechBlog
    May 1, 2013 - 11:15 pm

  2. Interesting .NET Links – May 5 , 2013 | TechBlog
    May 5, 2013 - 10:59 pm

  3. Interesting .NET Links – May 8 , 2013 | TechBlog
    May 8, 2013 - 11:25 pm

Leave a Comment


You might be Interested in these Posts

How to read connection string from web.config in ASP.NET and C# ?

Here's a sample code snippet demonstrating how to get the connection string from your ASP.NET

How to return Json instead of XML in ASP.NET Web API ?

When you make a call to the ASP.NET Web API action method and notice this in Google Chrome browser ,...

How to Add Web API to existing ASP.NET Web Forms Project ?

In one of the previous posts , we saw how to add the WebAPI to the existing ASP.NET MVC project. Wel...