c# - Passing derived class around via base class property on controller -
i'm building wizard-style multi-step process in asp.net mvc 4 web application. i'm using tempdata hang on info before steps, because wizard isn't strictly linear - user's choices on first page result in them seeing 1 of 3 options 3rd page. i'm achieving using selection assign 1 of 3 derived classes base-class property on viewmodel 3rd page. page uses custom model binder allow me utilize @html.editorfor(m => m.basecontainer) , have display right template user fill in. problem when 3rd page posts back, controller method of course of study expecting base-class object, means when save in tempdata, saves base of operations class properties.
i series of checks along lines of if (viewmodel.basecontainer derivedclass1), seems hack. whole point of abstraction in using base of operations class controller doesn't need know 1 @ point. there more elegant way save object without losing properties of derived class?
we tackled same problem several months ago, solved using smaller view model each step in wizard , on successful validation, copied values big view model (containing properties in wizard). stored big view model in tempdata , progressed next step.
if you're adding new properties when deriving base of operations class, extending it's interface, create interfaces new properties in each derived class, sounds non simple solution.
c# asp.net-mvc-3 inheritance asp.net-mvc-4 polymorphism
No comments:
Post a Comment