Sebastian K
Sebastian K

Reputation: 6403

Usage of QueryString parameters in MVC with HTTP Post

I was recently debugging an ASP.NET MVC application (Firefox + Firebug) and I ran into interesting (to me) scenario, all GET requests as expected were passing parameters in querystring, most POST requests were just posting inputs in the form, however there were some POST requests that mixed both querystring parameters and form inputs.

Interestingely enough MVC model binder had no problem at all to build a model from a mix of querystring and posted parameters. Is it a valid and accepted pattern in ASP.NET MVC and HTTP, or is it more of a fault-tolerant implementation of model-binder?

Upvotes: 0

Views: 1690

Answers (1)

Filip W
Filip W

Reputation: 27187

This is by design - the default MVC model binder will try to match the model parameters from both the URI (query string and/or route data) and the body.

Of course, you could implement your own model binder that behaves differently.

By the way, in ASP.NET Web API, this behavior is no longer like that, and the URI and body parameters are not mixed.

Upvotes: 2

Related Questions