ASP.NET MVC doesn't work with ViewState and Postback?

后端 未结 3 1302
故里飘歌
故里飘歌 2020-12-02 15:49

Perhaps this is a naive question. In my understanding, ASP.NET MVC cannot work with ViewState and Postback which is fundamentals of ASP.NET forms. Is that correct?

I

相关标签:
3条回答
  • 2020-12-02 16:29

    ASP.NET's server-side controls work with WebForms, not MVC. MVC doesn't use controls in the traditional ASP.NET sense (at least yet).

    The MVC model is quite different from the WebForms model; not better or worse, but very different. Using MVC puts the developer much closer to the generated HTML, lends itself more intrinsically to unit testing, and provides a strong separation of concerns between the UI and the code that populates that UI.

    At first glance, especially to hardened ASP.NET veterans, MVC can seem like a huge step backwards (if you've were coding then, visions of ASP COM development might dance in your head).

    But give MVC a try. It is very interesting and its model is quite compelling once you get used to it.

    Read more here: http://quickstarts.asp.net/previews/mvc/mvc_HowToRenderFormUsingHtmlHelpers.htm

    Also, check out this interesting blog engine that uses MVC: http://www.codeplex.com/oxite

    Finally, check out Rob Conery's MVC storefront project: http://wekeroad.com/category/mvc-storefront

    0 讨论(0)
  • 2020-12-02 16:37

    This might surprise you, but I accidentally dropped a Button on a MVC page, and implemented the Click event, and it actually worked!

    I was surprised, maybe it works for just this simple case (it was the only element on the page at that time), and the fact that the response ended with a redirect, but in some cases it seems it can work :)

    0 讨论(0)
  • 2020-12-02 16:42

    This might surprise you, but I accidentally dropped a Button on a MVC page, and implemented the Click event, and it actually worked!

    Please correct me if I'm wrong, but I think the does not need a ViewState. It should create a simple HTML tag , and if you don't change the properties of the button at run-time (text, event, ...), no VIEWSTATE will be needed.

    Maybe that's the reason why it worked.

    0 讨论(0)
提交回复
热议问题