2

I'm wondering why query string is preferred when getting values from user request. Where? 1) Code of System.Web.Mvc.DefaultModelBinder looks like this (only part of it):

HttpRequestBase request = controllerContext.HttpContext.Request;
    if (request != null)
    {
        if (request.QueryString != null)
        {
            values = request.QueryString.GetValues(modelName);
            attemptedValue = request.QueryString[modelName];
        }
        if ((values == null) && (request.Form != null))
        {
            invariantCulture = CultureInfo.CurrentCulture;
            values = request.Form.GetValues(modelName);
            attemptedValue = request.Form[modelName];
        }
    }

2) If I have a method in controller with this signature:

public ActionResult Save(int? x, string y) {...

the parameters (x, y) are bound to values from query string, not from form. I would expect that values from Request.From have higher priority than from Request.QueryString.

Edit: I see that the second case is caused by the first one (DefaultModelBinder), am I right?

What's the motivation behind?

1
  • it's 6 one way, half dozen the other. I think it probably applies to Darryl's post below with consistency Commented Oct 2, 2008 at 19:04

1 Answer 1

1

Consistency probably.

The query string has been the default since the original ASP model. If you want to get data the form you have always needed to get the values from there explicitly if the same names are also on the querystring.

Sign up to request clarification or add additional context in comments.

1 Comment

What's the precedence for cookie values?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.