views:

815

answers:

1

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  A: 

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.

Darryl Braaten