mvc model binding

21
ASP.NET MVC Model Binder Jason

Upload: learningtech

Post on 13-Jun-2015

1.207 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: MVC Model Binding

ASP.NET MVC Model BinderJason

Page 2: MVC Model Binding

Class map

Page 3: MVC Model Binding

Agenda

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

Page 4: MVC Model Binding

Model Binder

Page 6: MVC Model Binding

Binding To Primitive Values

Controller:

View:

Page 7: MVC Model Binding

Binding To Simple Objects

Page 8: MVC Model Binding

Binding To Collection Of Objects

Controller:

View:

Page 9: MVC Model Binding

FormCollection Model Binder

UpdateModel Syntax

example

Page 10: MVC Model Binding

Formcollection Model Binder

UpdateModel Syntax

example

Page 11: MVC Model Binding

HttpPostedFileBase Model Binder

View:

Controller:

Page 12: MVC Model Binding

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.

Page 13: MVC Model Binding

Binding Attribute

Page 14: MVC Model Binding

Custom Model Binder

Step1 You bind your custom object by implementing

the IModelBinder interface.

Page 15: MVC Model Binding

Custom Model Binder

Step2 After creating your binder, you need to register

the binder. In Application_Start().

Page 16: MVC Model Binding

Custom Model Binder

PersonModelBinder

Submit

Binding

Page 17: MVC Model Binding

Custom Model Binder

The first is by decorating the model class

Page 18: MVC Model Binding

Custom Model Binder

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

Page 19: MVC Model Binding

Summary

Easy Flexible Customize

Page 20: MVC Model Binding

Q & A