I came to know there is no viewstate in MVC.
I have two question with respect to view state.
first question:
In classic web forms Viewstate is used to maintain control states during round trips. even i am not clear with this point. I read somewhere like if i disable viewstate in a page all the forms controls will be cleared after postback. I don’t feel this is a valid reason for the need of a viewstate. The ASP.net engine could handle this situation (mainatianing state) without viewstate.
and my second question: which part of MVC is handling view state responsibility.
Regards,
Ramana Akula.
ViewState is not needed because there are no server-side controls (at least there shouldn’t be).
Simple as that really.
Server-side controls use ViewState to track (in some cases all) property values that need to be restored when the page is posted back. Equally, it’s the mechanism by which server-side events such as
TextChangedcan be fired – the server re-hydrates theasp:TextBox‘sTextvalue as it was when the ViewState was saved into the page, and compares it to the value that is POSTed back – if it’s different, the event is fired. For example.In truth ViewState is a very clever solution… But I have to say I loathe it.
In MVC, when a text-box is rendered (or, should I say, an HTML input
type=text) and then submitted back, it’s value is re-bound back from the request. On the server you then reconstitute the data you need to compose the view again.I’ve written quite a few MVC sites now – and I’ve not even had a need to switch on session state yet.
If you’re coming from Asp.Net Forms it can be totally mind-boggling at first (it really depends on how comfortable you are with HTML in general), but ultimately it’s incredibly liberating; and obviously makes a huge difference with performance.