views:

361

answers:

3

I'm looking in ASP.NET MVC source and don't found where ViewState is removed from application.

(The ViewState is not just disabled, it is removed of all pages in application)

Thanks!

Update:

Is remove Viewstate hidden field possible?

+3  A: 

That's easy; it isn't removed. You can still set and read ViewState. Just don't expect it to contain anything from the previous request. This is actually convenient, because it means that certain ASP.NET server controls which store their property values in ViewState can be made to work in ASP.NET MVC. As long as it's not important to persist ViewState from one request to another, these controls still work fine.

Removing the persistence of ViewState from one request to another makes it close to useless, of course. This is why people generally say that ASP.NET MVC "doesn't have ViewState." This isn't technically accurate; ViewState actually does exist; it just doesn't exist in a form which is useful for anything.

Craig Stuntz
I understand that ViewState is never removed. Responding my update: In "normal ASP.NET" (PostBack) not is possible remove ViewState hidden input, for hide it in HTML page just remove runat="server" in form. Thanks!
Wagner Andrade
ASP.NET MVC will never put a ViewState field into your page. The WebForms *designer* will add this field once your MVC pages, however, which is one of many good reasons not to use it with MVC views. It is entirely safe to remove this hidden input.
Craig Stuntz
+4  A: 

MVC does not use the viewstate - it is completely stateless (as the web should be).

You may have to change your mindset a little and think about your apps running under a request-response model (which it always has, but standard asp.net used viewstate to try and "trick" the developer, if you will, into thinking, or coding as if a page had state.)

Paul
A: 

ViewState is not a part of the ASP.NET MVC page life cycle. ViewState is only available in ASP.NET WebForms applications.

This also means that you are not able to use most of the ASP.NET WebForms controls which rely on ViewState

Mark