Can a asp.net mvc view page have a webform control on it?

前端 未结 4 623
心在旅途
心在旅途 2021-01-13 17:52

Can a asp.net mvc view page have a webform control on it?

I think I read about it before, but I\'m not sure how it would work since MVC doesn\'t use viewstate etc?

相关标签:
4条回答
  • 2021-01-13 18:16

    Don't forget that MVC implements REST so ViewState is now pretty much obsolete unless you implement it yourself using say hidden fields.

    About the only thing that the WebForm controls were good for was Ajax IMHO.

    If you replace WebForm Controls with Partial Views, WebControl classes and jQuery plugins then you can achive the same.

    I'm currently leaning towards writing my own WebControls and jQueryPlugins and referencing them within PartialViews.

    There are heaps of jQuery plugins now available which perform pretty much all the actions that the WebForm controls did.

    0 讨论(0)
  • 2021-01-13 18:18

    Not most web controls because they depend on ControlState and in some cases ViewState. Third parties like Telerik are adapting their controls to get around this, however the long-term goal is for people to build new controls that are more built around standards like JavaScript, jQuery, JSON, etc.

    0 讨论(0)
  • 2021-01-13 18:27

    What I know for sure is that any control that implements IPostBackEventHandler or IPostBackDataHandler will fail automatically -- they will throw an exception saying you need a <form runat="server">

    That said, you should avoid using ASP.NET WebForms server controls in your MVC applications.

    0 讨论(0)
  • 2021-01-13 18:35

    It can, but the Viewstate is not available. So, If the control relies on the viewstate, it may malfunction.

    Also, events will not be readily available.

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