-1

Every time I look at an MVC action method, I find a new feature.

  • First, it seems to pull in route parameters automatically into matching parameter names (e.g. "id"), along with form fields, query strings, and cookies.
  • Then I discover that if you include the strongly-typed ViewModel as a parameter, it automatically populates its members from form fields/controls.
  • Now, I see in Microsoft's scaffolding for a new controller with read/write, it sticks a FormCollection parameter on post actions that presumably is automatically populated with form field values (e.g. the precursor to a strongly-typed model?)

What other magic happens with action method parameters?

The last one in particular surprised me, because it's not mentioned anywhere in the documentation, such as under "Automatically Mapping Action-Method Parameters" here: https://msdn.microsoft.com/en-us/library/dd410269%28v=vs.100%29.aspx

Triynko
  • 18,766
  • 21
  • 107
  • 173
  • Discovered another just since writing this post. The strongly-typed model can have custom binding behavior by adding an attribute to the method parameter: [ModelBinder(typeof(CustomModelBinder))], where CustomModelBinder implements IModelBinder (or inherits from DefaultModelBinder, which already implements the interface). – Triynko Aug 27 '15 at 19:15

1 Answers1

0

Here is some general information from Microsoft on how Web API binds parameters, but I think you have covered most of the information yourself.

http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api

Matthew
  • 777
  • 1
  • 9
  • 23