36

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?

Clarice Bouwer
  • 3,631
  • 3
  • 32
  • 55
Matt Mitchell
  • 40,943
  • 35
  • 118
  • 185

3 Answers3

32

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

Brandon Wood
  • 5,347
  • 4
  • 38
  • 31
21

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)

Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
  • i had a same problem but your answer help me a lot. i have an another question whether we can pass query string-vale and Form-value in single request. is it practically possible? – Kumaran T Aug 03 '11 at 12:05
1

The reason was that the value I was retrieving was from a form element, but the submit was done through a link + JQuery, not through a form button submit.

Matt Mitchell
  • 40,943
  • 35
  • 118
  • 185