asp.net mvc - Building a complex Object step by step. Where to save it? -


I am using ASP.NET mvc through a step-by-step process like my wizard Creating a complex object (Object made from other object)

Every dependent object will be constructed at its stage and validated in its phase. For example

  public square premise object model {public object 1 MyObject1 {get; Set; } Public Object 2 {Receive MyObject1; Set; } Public Object3 MyObject1 {get; Set; }}  

There is no built-in feature for a wizard, so I have decided to create 3 model classes and 3 strong type partial scenes associated with these models.

At every step of my pseudo-wizard, I accept the dependent model object and set the complex object's property in its context.

I was thinking of saving complex objects inside ViewData / TempData as follows

In the operation of the controller

  [http post] Public ActionResults Mayne 1 () {View Complex Object Model Code = (Complex Object Model) Data ["Complex Object Model"]; Com.MyObject1 = New Object 1 (); See data ["Complex objectModel"] = com; Back partial view ("MyAction2", com.Object1); }  

See more

  using <% (Html.BeginForm ()) {%> & Lt;% = Html.Hidden ("Complex Object Model", see Data ["Complex Object Model"])% & gt; ... object1, object n .... and lift;%}%>  

But in this way the object has been passed and not passed further between the controller and I have experienced that when it comes back from the scene to come back to the next action.

Is there any way to support this requirement?

Thanks for helping

There are some ways that I can face it Was there.

First of all; I can decide to store all this session object. I am here to assume that the models are quite big and that's why I do not want to store them on the scene and whenever I want to go to the next page, I will be sent back.

Second; I can store them in the database and if the wizard is unable to complete, then remove them as part of the background process.

One thing I do not do is that complex objects pass for each scene. Vision really needs to know something about any other scene that is in a sad world and therefore I do not want to do it.

Of course it means that you need to decide on a storage location for the data. If I had large objects then I wanted to choose the database and if I was too small, then I chose the session object.

As you've already done, each data in each object can be problematic in each view.

However, if you determine the way to see it, then that is what I am doing;

  1. Create partial views that only have a complex view of each object.
  2. On each view, include all three or more partial ideas.
  3. For each partial view that is not an active participant in the scene, place it inside a div that is hidden.

At least then when you change a property, or add one, you do not set it once in three times in a partial view. Also, if there is an error, then You can see the devices and see whether the data is coming or not.

In addition, each field should have property of the model name so that the controller will know where the asset is.

  & lt;% = Html.TextBox ("MyObject1.MyProperty1", value)%>  

Then you just do in the controller, and this cuff is closed;

  [HTTP Post] Public Function MyAction1 (Complex Object Model Complex Model) { 

Comments