Asp.net-3.5

有沒有辦法在 WebForms 中呈現部分視圖?

  • October 6, 2012

我正在接觸一個舊的WebForms project,但我早就離開了它,我現在已經習慣了 MVC。我正在嘗試重構項目並提出一個讓我發瘋的簡單問題……

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

我不想僅僅為此而擁有很多主文件,我所追求的只是某種東西@Html.RenderPartial("MyFileName")

在某些現有文件中包含文件有那麼難嗎?

在 UserControl 上使用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>

引用自:https://stackoverflow.com/questions/12761000