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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Request.Form only includes variables posted through a form, while Request.Params includes both posted form variables and get variables specified as URL parameters.
Method 2
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)
Method 3
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0