[英]ASP.NET/UserControls: How do I separate the “controller” from the “view”?
Is it possible to separate the ascx ("view") and the ascx.cs ("controller") pars of a user control.是否可以将用户控件的 ascx(“视图”)和 ascx.cs(“控制器”)pars 分开。 Id like to move the controller part to App_Code to be resued while the view part is changed between projects?
我想将 controller 部分移动到 App_Code 以在项目之间更改视图部分时重新使用?
Yes, write the codebehind in some service class which extends UserControl, and in your.ascx file inherit that class是的,在扩展 UserControl 的某些服务 class 中编写代码隐藏,并在 your.ascx 文件中继承该 class
<%@ Control
Language = "C#"
Inherits = "Project.Business.Service.MyControl"
%>
In regular ASP.NET, even if you separate the code-behind and the ascx - they are still tightly coupled.在常规 ASP.NET 中,即使您将代码隐藏和 ascx 分开 - 它们仍然是紧密耦合的。 It isn't a true "controller" (as separate from a view).
它不是真正的“控制器”(与视图分开)。
If you want this purity, consider ASP.NET MVC, which (obviously) addresses this in a different way.如果您想要这种纯度,请考虑 ASP.NET MVC,它(显然)以不同的方式解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.