简体   繁体   English

asp.net mvc视图页面上有一个webform控件吗?

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

Can a asp.net mvc view page have a webform control on it? asp.net mvc视图页面上有一个webform控件吗?

I think I read about it before, but I'm not sure how it would work since MVC doesn't use viewstate etc? 我想我以前读过它,但我不确定它是如何工作的,因为MVC不使用viewstate等?

It can, but the Viewstate is not available. 它可以,但Viewstate不可用。 So, If the control relies on the viewstate, it may malfunction. 因此,如果控件依赖于视图状态,则可能会出现故障。

Also, events will not be readily available. 此外,活动不会随时可用。

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"> 我所知道的是,任何实现IPostBackEventHandler或IPostBackDataHandler的控件都会自动失败 - 它们会抛出一个异常,说你需要一个<form runat="server">

That said, you should avoid using ASP.NET WebForms server controls in your MVC applications. 也就是说,您应该避免在MVC应用程序中使用ASP.NET WebForms服务器控件。

Don't forget that MVC implements REST so ViewState is now pretty much obsolete unless you implement it yourself using say hidden fields. 不要忘记MVC实现了REST,所以ViewState现在已经过时了,除非你自己使用say hidden fields实现它。

About the only thing that the WebForm controls were good for was Ajax IMHO. 关于WebForm控制的唯一的东西是Ajax恕我直言。

If you replace WebForm Controls with Partial Views, WebControl classes and jQuery plugins then you can achive the same. 如果用部分视图,WebControl类和jQuery插件替换WebForm控件,那么你可以实现相同的功能。

I'm currently leaning towards writing my own WebControls and jQueryPlugins and referencing them within PartialViews. 我目前倾向于编写自己的WebControls和jQueryPlugins并在PartialViews中引用它们。

There are heaps of jQuery plugins now available which perform pretty much all the actions that the WebForm controls did. 现在有大量的jQuery插件可以执行WebForm控件所做的几乎所有操作。

Not most web controls because they depend on ControlState and in some cases ViewState. 不是大多数Web控件,因为它们依赖于ControlState,在某些情况下依赖于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. 像Telerik这样的第三方正在调整他们的控制来解决这个问题,但是长期目标是让人们构建更多基于JavaScript,jQuery,JSON等标准的新控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM