model binding

Post on 30-Jul-2015

280 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

ASP.NET MVC Model BinderJason

Class map

Agenda

Default Model Binder FormCollection Model Binder HttpPostedFileBase Model Binder Binding Attribute Custom Model Binder

Model Binder

Binding To Primitive Values

Controller:

View:

Binding To Simple Objects

Binding To Collection Of Objects

Controller:

View:

FormCollection Model Binder

UpdateModel Syntax

example

Formcollection Model Binder

UpdateModel Syntax

example

HttpPostedFileBase Model Binder

View:

Controller:

Binding Attribute

Include Gets or sets a comma-delimited list of property names for which

binding is allowed.

Exclude Gets or sets a comma-delimited list of property names for which

binding is not allowed.

Binding Attribute

Custom Model Binder

Step1 You bind your custom object by implementing

the IModelBinder interface.

Custom Model Binder

Step2 After creating your binder, you need to register

the binder. In Application_Start().

Custom Model Binder

PersonModelBinder

Submit

Binding

Custom Model Binder

The first is by decorating the model class

Custom Model Binder

The second is decorating the parameter of your Action Method directly:

Summary

Easy Flexible Customize

Q & A

top related