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?


Thanks.
Razor demo:
http://www.w3schools.com/razor/showfile_c.asp?filename=try_razor_9



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

Open in new window

newbiewebSr. Software EngineerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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.

Summary:

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.




0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0
All Courses

From novice to tech pro — start learning today.