0

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

kaivalya
  • 4,611
  • 4
  • 26
  • 28
  • What's wrong with storing it client side? – Mehrdad Afshari Mar 27 '09 at 22:31
  • you realize that storing it in the ViewState actually WAS storing it on the client side? – Al W Mar 27 '09 at 22:33
  • Storing on client side to seems like it is becoming extra maintenance. To handle properly I need to create JS version of my classes and populate store the data in them. So 1. I need to duplicate the class structure that i already have on the server 2. i will need to maintain it. – kaivalya Mar 28 '09 at 01:25
  • Don't get me wrong though I am not putting an end to client side approach I am open and willing to challenge my view on it - I am just not clear why I need to go through that effort. – kaivalya Mar 28 '09 at 01:28

3 Answers3

0

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
  • 74
  • 6
0

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: ASP.NET MVC - Is there a way to simulate a ViewState?. 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): ASP.NET MVC controller actions design

Community
  • 1
  • 1
Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
  • 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 Mar 28 '09 at 14:26
0

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
  • 9,331
  • 2
  • 22
  • 22