Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do Request.Params and Request.Form differ?

I recently encountered a problem where a value was null if accessed with Request.Form but fine if retrieved with Request.Params. What are the differences between these methods that could cause this?

like image 971
Matt Mitchell Avatar asked Aug 08 '08 05:08

Matt Mitchell


People also ask

What is the difference between query string params and form data params?

Form the data is posted in http header whereas in QueryString data is sent through url. Request. Form is used for accessing the value on post back of form and Request. QueryString is used for accessing the value passes in url as a parameter.

What is the use of request QueryString and Request Form?

Form, the Web server parses the HTTP request body and returns the specified data. If your application requires unparsed data from the form, you can access it by calling Request. Form without any parameters. The QueryString collection retrieves the values of the variables in the HTTP query string.


2 Answers

Request.Form only includes variables posted through a form, while Request.Params includes both posted form variables and get variables specified as URL parameters.

like image 118
Brandon Wood Avatar answered Sep 26 '22 03:09

Brandon Wood


Request.Params contains a combination of QueryString, Form, Cookies and ServerVariables (added in that order).

The difference is that if you have a form variable called "key1" that is in both the QueryString and Form then Request.Params["key1"] will return the QueryString value and Request.Params.GetValues("key1") will return an array of [querystring-value, form-value].

If there are multiple form values or cookies with the same key then those values will be added to the array returned by GetValues (ie. GetValues will not return a jagged array)

like image 30
Richard Szalay Avatar answered Sep 24 '22 03:09

Richard Szalay