如果MVC2使用aspx页面和母版页可以使用asp.net服务器控件吗?

发布于 2025-01-01 10:27:09 字数 133 浏览 2 评论 0原文

我注意到 MVC 2 使用母版页和 ascx 页面。我习惯使用 Razor 页面,但必须处理较旧的项目。所以我想知道在这些 aspx 标记页面上使用 asp.net 服务器控件是否可以?

我知道建议不要插入页面生命周期,但是用户控件呢?

Ive noticed that MVC 2 uses masterpages and ascx pages. I'm used to using Razor pages but have to work on an older project. So I'm wondering if it is okay to use asp.net server controls on these aspx markup pages?

I know its advised not to plug into the page lifecycle but what about user controls?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧城空念 2025-01-08 10:27:09

如果您想使用用户控件,请坚持使用 Web 表单。用户控件不与 MVC 一起使用。 MVC 视图引擎没有像 Web 窗体那样的页面生命周期。

If you want to use user controls, stick with Web Forms. User controls are not used with MVC. The MVC view engine does not have a page lifecycle like Web Forms.

泼猴你往哪里跑 2025-01-08 10:27:09

您的用户控件插入到 WebForms 页面生命周期中,它们通过 ViewState 维护其状态。创建了一些帮助程序来将控件呈现给 MVC,但它们的局限性在于它们是只读的,控件不支持回发或任何类似的事件。

http ://malvinly.com/2011/02/28/using-web-forms-user-controls-in-an-asp-net-mvc-project/

您可以创建自己的部分控件:

在 MVC 项目中的 webform 上使用 webform 用户控件

Your Usercontrols plug in to the WebForms page lifecycle, they maintain their state through ViewState. There are helpers that were created to render out controls to MVC but they are limited in the fact that they are read-only, the controls don't support posting back or any events like that.

http://malvinly.com/2011/02/28/using-web-forms-user-controls-in-an-asp-net-mvc-project/

You could create partials out of your own controls:

Using webform user control on webform in MVC Project

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文