asp.net mvc - Is binding domain models directly a bad idea? -


i'm curious if binding models directly parameters in action method considered bad idea ?

if form gets complex, create custom model binder.

are there pitfals using approach ?

i'd avoid creating of viewmodel, because want keep me app simple possible. i'd avoid of duplicating code , modelview model binding.

i'd advise use view models.

if you're using default object templates... don't non-flat models, , while override them, it's not idea. domain models not flat. either way, based on modelmetadata easier viewmodel.

validation easier viewmodel, you've got more focused model, , there's validation makes sense in views.

creating viewmodels better , safer sending models using jsonresult... well... should never send domain models outside anyway, if you're not using viewmodels. it's easier using jsonresult when you've got viewmodel ready. it's easier make mistakes , expose sensitive information when you're used using domain models everywhere.

changes easier, because changing property on domain model doesn't mean have change views, change creation of viewmodel (if you're using kind of mapper, that's 1 change binding), although isn't strong point imo.

some other benefits decoupling presentation layer business layer, , if you're using ef or non-poco objects, it'll harder use them in views.

if want eliminate duplication of code, consider creating filters automatically create viewmodels, , without action filters using mapper eliminate lot of code duplication.

btw, don't see how creating custom model binder simpler using viewmodels.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -