My custom ASP.NET MVC entity binding: is it a good solution?

前端 未结 1 1817
时光说笑
时光说笑 2020-12-29 00:43

Suppose I want to allow to select our entity (from a dropdown, etc) on a page, let\'s say Product. As a result I may receive this:

public ActionResult Select         


        
1条回答
  •  时光说笑
    2020-12-29 00:53

    Overall that looks like a good appoach to me...

    As an alternative, you could use POCO for your viewmodel then I think all 3 problems would be solved automatically. Have you seen the Automapper project that allows an Entity to DTO approach? This would give you more flexibility by separating you ViewModel from your EntityModel, but really depends on the complexity of you application you are building.

    MVC's ViewDataExtensions might also be useful instead of creating custom containers to hold various viewmodel objects as you mention in number 2.

    MVCContrib's ModelStateToTempData should work for any serializable object (must be serializable for any out of process sessionstate providers eg. SQL, Velocity etc.), so you could use that even without wrapping your entity classes couldn't you?

    0 讨论(0)
提交回复
热议问题