【问题标题】:Is there a way to render Partial Views in WebForms?有没有办法在 WebForms 中呈现部分视图?
【发布时间】:2012-09-27 11:31:48
【问题描述】:

我正在接触一个旧的WebForms project,但我早就离开了它,现在我已经习惯了 MVC。我正在尝试重构项目并提出一个让我抓狂的简单问题......

.aspx 文件包含在另一个文件中的最佳方式是什么?

我不想仅仅为此而拥有很多主文件,我所追求的只是@Html.RenderPartial("MyFileName") kind'a thingy 或

在某些现有文件中包含文件有那么难吗?

【问题讨论】:

    标签: asp.net-3.5 webforms


    【解决方案1】:

    使用UserControlTutorial on UserControl。它们是带有.ascx 扩展名的文件,您可以将它们包含在您的页面中

    //UserControl1.ascx
    <% @ Control Language="C#" ClassName="UserControl1" %>
    
     <div>
       My Custom Control: I can use any Server controls, html tags etc
     </div>
    

    将其包含在您的 .aspx 页面中

    <%@ Page Language="C#" %>
    <%@ Register TagPrefix="uc" TagName="MyCustomControl" Src="~/Controls/UserControl1.ascx" %>
    <html>
    <body>
    <form runat="server">
        <uc:MyCustomControl id="MyPartialView" 
            runat="server" />
    </form>
    </body>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 2010-12-01
      相关资源
      最近更新 更多