在ASP.NET MVC中使用ASP.NET Web窗体UserControl?

时间:2021-08-24 15:16:21

I've been tasked with making a prototype web application, and i'm debating between using ASP.NET WebForms or the new ASP.NET MVC.

我的任务是创建一个原型Web应用程序,我正在讨论使用ASP.NET WebForms或新的ASP.NET MVC。

There is a commerical ASP.NET UserControl that i would like to use that gives me 95% of the functionality i need (and it does it in an AJAX-y fashion). But i've heard that since ASP.NET MVC doesn't use ViewState, it can't run these WebForms-based controls.

有一个我想使用的商业ASP.NET UserControl,它提供了我需要的95%的功能(并且它以AJAX-y方式实现)。但我听说,由于ASP.NET MVC不使用ViewState,它无法运行这些基于WebForms的控件。

So, is that true or false?

那么,这是真是假?

I'd really like to use this commerical UserControl, but i want to use ASP.NET MVC if i can, and only if ASP.NET MVC is not going to give me much trouble when trying to use the WebForms-based control.

我真的很想使用这个商业用户控件,但是如果可以的话我想使用ASP.NET MVC,并且只有当ASP.NET MVC在尝试使用基于WebForms的控件时不会给我带来太多麻烦时。

2 个解决方案

#1


8  

Traditional WebForms and MVC aren't mutually exclusive; you could run both of them in the same site. For an explanation of how to make this happen, see this post by Scott Hanselman.

传统的WebForms和MVC不是互斥的;你可以在同一个站点运行它们。有关如何实现这一点的解释,请参阅Scott Hanselman的这篇文章。

So you could, for example, create WebForms-based page(s) to leverage the commercial control, and use MVC for everything else. You could also set up a simple test to see if the control can operate without ViewState -- making it OK to use in MVC -- and fall back on the hybrid approach.

例如,您可以创建基于WebForms的页面来利用商业控件,并将MVC用于其他所有内容。您还可以设置一个简单的测试,以查看控件是否可以在没有ViewState的情况下运行 - 可以在MVC中使用 - 并且可以依靠混合方法。

#2


0  

It probably won't work. There is no viewstate, postbacks (in the Webforms sense) or page lifecycle which most commercial controls rely on in some fashion.

它可能不会起作用。没有viewstate,postbacks(在Webforms意义上)或页面生命周期,大多数商业控件都以某种方式依赖它们。

#1


8  

Traditional WebForms and MVC aren't mutually exclusive; you could run both of them in the same site. For an explanation of how to make this happen, see this post by Scott Hanselman.

传统的WebForms和MVC不是互斥的;你可以在同一个站点运行它们。有关如何实现这一点的解释,请参阅Scott Hanselman的这篇文章。

So you could, for example, create WebForms-based page(s) to leverage the commercial control, and use MVC for everything else. You could also set up a simple test to see if the control can operate without ViewState -- making it OK to use in MVC -- and fall back on the hybrid approach.

例如,您可以创建基于WebForms的页面来利用商业控件,并将MVC用于其他所有内容。您还可以设置一个简单的测试,以查看控件是否可以在没有ViewState的情况下运行 - 可以在MVC中使用 - 并且可以依靠混合方法。

#2


0  

It probably won't work. There is no viewstate, postbacks (in the Webforms sense) or page lifecycle which most commercial controls rely on in some fashion.

它可能不会起作用。没有viewstate,postbacks(在Webforms意义上)或页面生命周期,大多数商业控件都以某种方式依赖它们。