MirSa
MirSa

Reputation: 1

a good substitute for viewstate in MVC?

I have an edit form in MVC. It contains different fields and 3 different partial views which is used like usercontrols. The scenario in these partial view: they contain a list with edit and delete plus an add button that when these buttons click a dialog box pop ups which contains a few related fields.

My main question is that what is the best solution to temporary save the changes of the lists(like viewstates)?

I'm asking because the main edit page contains more fields and I want in the case that the save button in the form is pressed, the whole data can be saved in database!(the tables in partial views has foreign key of the table of the main page).

Thank you in advance!

Upvotes: 0

Views: 1089

Answers (1)

amhed
amhed

Reputation: 3659

The web is stateless in its nature. Instead of looking for a workaround on the whole ViewState thing, it's better to try and embrace the medium you're using.

If you have many controls rendered on the same page you can either:

  • Use HTML5 Local Storage and persist on the client before submitting the whole form. There are many frameworks that will help you persist a form on the client side like Sysyphus.js
  • Make use of asynchronous ajax calls if you need to persist data on user input before submitting the whole form. Client-side calls can be managed using jQuery's ajax() function with ease and you can make use of the ASP.NET Web API to build the end-point on the server.

Upvotes: 1

Related Questions