8

I like to know the order of the execution of the different ValueProviders in ASP.NET MVC.

ValueProviders:

  • QueryStringValueProvider
  • RouteDataValueProvider
  • FormValueProvider
  • ...

I did not find an information.

Rookian
  • 19,841
  • 28
  • 110
  • 180
  • 3
    How about this? ASP.NET MVC / Web API / Web Pages - Source Code http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/e599230bf8ac#src/System.Web.Mvc/ValueProviderFactories.cs – takepara Dec 19 '12 at 01:53

2 Answers2

8

If memory serves me, the priority is like this.

  1. Form data in the request
  2. Route data
  3. Query String
  4. Http File Collection

EDIT I appear to be in agreement with the following website, which lists the same order. http://www.howmvcworks.net/OnModelsAndViewModels/TheBeautyThatIsTheModelBinder

KingCronus
  • 4,509
  • 1
  • 24
  • 49
4

You can check this out from ASP.NET MVC source code: ValueProviderFactories.cs

Here is the predefined order for ValueProviders:

    private static readonly ValueProviderFactoryCollection _factories = new ValueProviderFactoryCollection()
    {
        new ChildActionValueProviderFactory(),
        new FormValueProviderFactory(),
        new JsonValueProviderFactory(),
        new RouteDataValueProviderFactory(),
        new QueryStringValueProviderFactory(),
        new HttpFileCollectionValueProviderFactory(),
    };
Will Huang
  • 2,955
  • 2
  • 37
  • 90