Model binding

21
ASP.NET MVC Model Binder Jason

Transcript of Model binding

Page 1: Model binding

ASP.NET MVC Model BinderJason

Page 2: Model binding

Class map

Page 3: Model binding

Agenda

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

Page 4: Model binding

Model Binder

Page 6: Model binding

Binding To Primitive Values

Controller:

View:

Page 7: Model binding

Binding To Simple Objects

Page 8: Model binding

Binding To Collection Of Objects

Controller:

View:

Page 9: Model binding

FormCollection Model Binder

UpdateModel Syntax

example

Page 10: Model binding

Formcollection Model Binder

UpdateModel Syntax

example

Page 11: Model binding

HttpPostedFileBase Model Binder

View:

Controller:

Page 12: 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: Model binding

Binding Attribute

Page 14: Model binding

Custom Model Binder

Step1 You bind your custom object by implementing

the IModelBinder interface.

Page 15: Model binding

Custom Model Binder

Step2 After creating your binder, you need to register

the binder. In Application_Start().

Page 16: Model binding

Custom Model Binder

PersonModelBinder

Submit

Binding

Page 17: Model binding

Custom Model Binder

The first is by decorating the model class

Page 18: Model binding

Custom Model Binder

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

Page 19: Model binding

Summary

Easy Flexible Customize

Page 20: Model binding

Q & A