Maintain browsing in Asp.net mvc?

One of the main reasons for using web forms is the ease of maintaining view state. I would like to create an asp.net mvc application, so what options do I have to maintain viewstate?

respectfully

+8
c # asp.net-mvc viewstate
Aug 16 '09 at 22:51
source share
4 answers

ASP.NET MVC does not use ViewState in the traditional sense (storing control values ​​on a web page). Rather, the values ​​of the controls are sent to the controller method. After calling the controller method, what you do with these values ​​is up to you.

ASP.NET MVC will keep the values ​​of the controls long enough for you to check them and (if necessary) to close them back to the page for editing or correction. If the checks are validated, you can save them in a database or other data warehouse, where they will be available for subsequent GET requests.

+9
Aug 16 '09 at 22:58
source share

You can simulate the view state by serializing the model using the MVC3Futures project

All you have to do is serialize the model and encrypt it in sight.

@Html.Serialize("Transfer", Model, SerializationMode.EncryptedAndSigned) 

And in the controller add a deserialized attribute.

 public ActionResult Transfer(string id,[Deserialize(SerializationMode.EncryptedAndSigned)]Transfer transfer) 
+6
Mar 20 '13 at 8:54
source share

Due to its basic business layer service structure, separate from the presentation layer, the MVC Framework does not allow you to save state via HTTP,

However, cookies, Serializable classes, ViewData and ViewBag are good ways to save state in MVC.

+6
Sep 25 '17 at 8:33
source share

If you want to create, for example, a stylized Wizard form, you can create a Serializable class to save the viewstate:

 [Serializable] public class MyWizard { public string Field1 { get; set; } public string Field2 { get; set; } } 

Then you can serialize this class and use it similarly to using ViewState (as a hidden field in a form).

0
Aug 16 '09 at 23:04
source share



All Articles