In asp.net pages, during postback, ViewState makes the data persistent. What makes the data persistent in ASP.net MVC?
ASP.NET MVC does not use ViewState in the traditional sense (that of storing the values of controls in the web page). Rather, the values of the controls are posted to a controller method.
View State is the method to preserve the Value of the Page and Controls between round trips. It is a Page-Level State Management technique. View State is turned on by default and normally serializes the data in every control on the page regardless of whether it is actually used during a post-back.
A partial view is a Razor markup file ( . cshtml ) without an @page directive that renders HTML output within another markup file's rendered output. The term partial view is used when developing either an MVC app, where markup files are called views, or a Razor Pages app, where markup files are called pages.
HTTP is a stateless protocol. Each HTTP request does not know about the previous request. If you are redirecting from one page to other pages, then you have to maintain or persist your data so that you can access it further.
The MVC tries to apply the concept of Http protocol statelessness!! So there should be no viewstate equivalent to that of the asp web forms. However in single page application, aka SPA : you use java script library on client to manage the page and contact the server using Ajax! So it gives the impression.
This article describes ASP.NET view state and shows with an example how view state works in ASP.NET. View State is the method to preserve the Value of the Page and Controls between round trips. It is a Page-Level State Management technique.
The ViewState is part of the WebForms framework, which you can combine with MVC. But ViewState is only available for .NET itself, not the .NET Core and other variants. The ViewState data depends on the Control.EnableViewState Property of any Control class that is used with WebForms. Is asp.net MVC really difficult?
The ViewState property is a dictionary that contains key/value pairs that contain the view state data. It is easy for a malicious user to see and modify the contents of a hidden field. For more information about how to secure view state data, see Securing View State later in this topic.
In Asp.Net we have Runat="Server" to make controls like Textbox,Checkbox... into asp.net controls which they run at server and they can maintain viewstate because of they are server controls.
Http is Stateless:
Http is stateless i.e; for it forgets the controls value (like Textbox,Checkbox) for every request that means it doesnt maintain state.To make stateful we use state management techniques like ViewState,Querystring,Sessions,Cookies in Asp.Net.
Coming to your Question
In MVC we dont have Viewstate.In order to maintain the values refer below link
Maintaining viewstate in Asp.net mvc?
ASP.NET MVC doesn't work with ViewState and Postback?
we use ViewBag,ViewData,TempData for the flow of values from controller to view or controller to controller .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With