Moved comment to number list correctly; italicized phrase (#2441)
parent
1d391bbb57
commit
5ce1578523
|
@ -42,19 +42,19 @@ MVC will try to bind request data to the action parameters by name. MVC will loo
|
|||
|
||||
2. `Route values`: The set of route values provided by [Routing](../../fundamentals/routing.md)
|
||||
|
||||
3. `Query strings`: The query string part of the URI.
|
||||
|
||||
<!-- DocFX BUG
|
||||
This link works bug generates an error when building with DocFX
|
||||
The link works but generates an error when building with DocFX
|
||||
@fundamentals/routing
|
||||
[Routing](xref:fundamentals/routing)
|
||||
-->
|
||||
|
||||
3. `Query strings`: The query string part of the URI.
|
||||
|
||||
Note: Form values, route data, and query strings are all stored as name-value pairs.
|
||||
|
||||
Since model binding asked for a key named `id` and there is nothing named `id` in the form values, it moved on to the route values looking for that key. In our example, it's a match. Binding happens, and the value is converted to the integer 2. The same request using Edit(string id) would convert to the string "2".
|
||||
|
||||
So far the example uses simple types. In MVC simple types are any .NET primitive type or type with a string type converter. If the action method's parameter were a class such as the `Movie` type, which contains both simple and complex types as properties, MVC's model binding will still handle it nicely. It uses reflection and recursion to traverse the properties of complex types looking for matches. Model binding looks for the pattern parameter_name.property_name to bind values to properties. If it doesn't find matching values of this form, it will attempt to bind using just the property name. For those types such as `Collection` types, model binding looks for matches to *parameter_name[index]* or just *[index]*. Model binding treats `Dictionary` types similarly, asking for *parameter_name[key]* or just *[key]*, as long as the keys are simple types. Keys that are supported match the field names HTML and tag helpers generated for the same model type. This enables round-tripping values
|
||||
So far the example uses simple types. In MVC simple types are any .NET primitive type or type with a string type converter. If the action method's parameter were a class such as the `Movie` type, which contains both simple and complex types as properties, MVC's model binding will still handle it nicely. It uses reflection and recursion to traverse the properties of complex types looking for matches. Model binding looks for the pattern *parameter_name.property_name* to bind values to properties. If it doesn't find matching values of this form, it will attempt to bind using just the property name. For those types such as `Collection` types, model binding looks for matches to *parameter_name[index]* or just *[index]*. Model binding treats `Dictionary` types similarly, asking for *parameter_name[key]* or just *[key]*, as long as the keys are simple types. Keys that are supported match the field names HTML and tag helpers generated for the same model type. This enables round-tripping values
|
||||
so that the form fields remain filled with the user's input for their convenience, for example, when bound data from a create or edit did not pass validation.
|
||||
|
||||
In order for binding to happen the class must have a public default constructor and member to be bound must be public writable properties. When model binding happens the class will only be instantiated using the public default constructor, then the properties can be set.
|
||||
|
|
Loading…
Reference in New Issue