What part of this Razor code updates the Request object?

In the attached demo, I see the Request["CompanyName"]; is updated since when it's a post back, the Request object has it.

Which line of code does that? And where is the controller specified?

Razor demo:

if (IsPost)
string companyname = Request["CompanyName"]; 
string contactname = Request["ContactName"]; 
<p>You entered: <br /> 
Company Name: @companyname <br /> 
Contact Name: @contactname </p> 
<form method="post" action=""> 
<legend>Add Customer</legend> 
<label for="CompanyName">Company Name:</label> 
<input type="text" name="CompanyName" value="" /> 
<label for="ContactName">Contact Name:</label> 
<input type="text" name="ContactName" value="" /> 
<input type="submit" value="Submit" class="submit" /> 

Open in new window

newbiewebSr. Software EngineerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Rouneh10Connect With a Mentor Commented:
Request is a property of the HttpContext object which is generated by ASP.NET for each request to the server. It contains a lot of information about the current request such as browser-information, form values, querystring variables and so on.

When the code: string companyname = Request["CompanyName"];  is evaluated, the Request object looks in the Form collection and the Querystring collection for matching keys and returns the value.

In this context, it could also have been written: string companyname = Request.Form["CompanyName"];

Note that none of these values come from the controller, but from the ASP.NET framework itself.


When you post a form to a ASP.NET page the ASP.NET framework generates a HttpRequest object.
In this HttpRequest object you will find information about the request made, such as Form values, browser-information and so on. (see http://msdn.microsoft.com/en-us/library/h55b6cak.aspx for full specification)
By default a razor page will have a reference to an instance of the current HttpRequest object in a property called Request.
By using Request["CompanyName"] you can return the value of the form-element named "CompanyName" from the posting form.

newbiewebSr. Software EngineerAuthor Commented:
All Courses

From novice to tech pro — start learning today.