views:

183

answers:

3

I have a data input module where I add the information of my product and its sub information like:

product basic info product price info product price details

price info and price details are related to product and are lists

In my web forms approach I would store my main product object on the view state and I would populate it's pricing info and details while doing ajax postbacks. This way I can create a compact module that is very user friendly in terms of defining a lot of data from one place without the need to enter these data from seperate modules. And when I am done I would do one product.save() and that would persist all the data to the respective tables on db.

Now I am building similar app on .net mvc framework and pondering on what would be the good way of handling this on mvc.

I don't resonate towards storing all this on client side till I click save. And saving to the db after each action makes me remember the days I was coding on asp.

Will appreciate your inputs on ways to approach this on mvc framework

A: 

I believe the best way of doing this is storing the data on the client side. It reduces unnecessary postbacks and improves responsiveness of your application. If you really want to store it on the server, you can use SessionState.

If you really want to store it in something like ViewState, you can go with a solution like this: http://stackoverflow.com/questions/669492/asp-net-mvc-is-there-a-way-to-simulate-a-viewstate/669495#669495. However, I recommend against it as it will make things more complicated. Doing it client-side is probably the most elegant way and storing it in SessionState is the easiest.

Remember that you can always escape the MVC pattern and use a simple Web form for that specific page (which will give you ViewState where you need it): http://stackoverflow.com/questions/594898/asp-net-mvc-controller-actions-design-question/598021#598021

Mehrdad Afshari
Please See my comments above. I am not clear why it would be the best way. Small postbacks on a data input module does not create much noticeable delay from user perspective but adds a high maintenance layer to the app..
kaivalya
A: 

store your Product list to the Model of the view and each time you change a value you can do a Ajax post to the controller and save the changes to the db, use partial views to display each item in your product list

Rony
A: 

you can try to integrate http://www.castleproject.org/ActiveRecord/ for easy saving and updating. That way you can just map your Model on your database using ORM(Object Relational Mapping). It takes a bit more work in the beginning but you will end up with simple commands like product.Update() and product.Create()

OhBugger