The community is working on translating this tutorial into Georgian, but it seems that no one has started the translation process for this article yet. If you can help us, then please click "More info".
If you are fluent in Georgian, then please help us - just point to any untranslated element (highlighted with a yellow left border - remember that images should have their titles translated as well!) inside the article and click the translation button to get started. Or have a look at the current translation status for the Georgian language.
If you see a translation that you think looks wrong, then please consult the original article to make sure and then use the vote button to let us know about it.
Please help us by translating the following metadata for the article/chapter, if they are not already translated.
If you are not satisfied with the translation of a specific metadata item, you may vote it down - when it reaches a certain negative threshold, it will be removed. Please only submit an altered translation of a metadata item if you have good reasons to do so!
Forms (POST data)
In the last article, we discussed the query string and how you can read parameters through it. This will usually happen through a so-called GET request, which will most frequently occur as a result of the user entering a URL in the browser or clicking on a link. As an alternative to the GET request we'll find the POST request. A POST request is usually initiated when the user submits a FORM (like a contact form or a login form). Unlike a GET request, where the data is visible in the URL, there's no visible data for the user in a POST request. For that reason, you need to use another property on the HttpContext class to pick up POST data: The Form property.
In ASP.NET MVC, the most common approach to dealing with forms is to bind the form to a Model. That means that each field of the form is tied to a property on the Model, allowing the form to read from the Model and also write to it, when the form is submitted. This is often referred to as Model Binding, and we'll discuss it elsewhere in this tutorial, but in this article, we'll access FORM data in the old, fashioned way.
Accessing FORM data
The Form property actually works a lot like the Query property - it acts as a Dictionary with keys and their values. So, when you submit a POST request to the Controller, e.g. by submitting a form, all the fields included will be added to the Form dictionary with their name as the Key and their value as the Value. Allow me to illustrate it with a simple example:
<form method="post" action="/Home/FormsTestPost">
<label for="txtName">Your name:</label>
<input type="text" id="txtName" name="UserName" />
<label for="txtAge">Your age:</label>
<input type="number" id="txtAge" name="UserAge" />
Just a basic HTML form. Notice how I set the method attribute to POST - forms support the GET method as well, but it's almost always better to use the POST method when dealing with forms.
My Controller could then look like this:
public class HomeController : Controller
public IActionResult FormsTest()
public IActionResult FormsTestPost()
return Content("Hello, " + HttpContext.Request.Form["UserName"] + ". You are " + HttpContext.Request.Form["UserAge"] + " years old!");
Notice how I can access the values of the FORM fields by referencing their names (UserName and UserAge, as defined in the name property of the form fields) in the Form collection.
Thanks to the HttpContext class and its Form property, accessing FORM/POST data is very easy in ASP.NET MVC. Using it is usually not necessary, thanks to Model Binding, but it's still useful in some cases.