【发布时间】:2011-06-29 19:28:31
【问题描述】:
我在局部视图中定义了一个部分,我想从视图中指定部分的内容。 但我想不出办法。在 asp.net 用户控件中,我们可以定义 asp:placeholders 和 从 aspx 中指定用户控制所在的内容。如有任何建议,我将很高兴。
谢谢
[编辑] 这是 asp.net 用户控件,我想将其转换为 razor 局部视图
用户控制:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SpryListView.ascx.cs" Inherits="SpryListView" %>
<div spry:region="<%=this.SpryDataSetName%>" id="region<%=this.ID%>" style="overflow:auto;<%=this.DivStyle%>" >
<table class="searchList" cellspacing="0" style="text-align:left" width="100%">
<thead>
<tr>
<asp:PlaceHolder ID="HeaderColumns" runat="server"></asp:PlaceHolder>
</tr>
</thead>
</table>
用户控制代码:
public partial class SpryListView : System.Web.UI.UserControl
{
private string spryDataSetName ;
private string noDataMessage = "Aradığınız kriterlere uygun kayıt bulunamadı.";
private bool callCreatePaging;
private string divStyle;
private ITemplate headers = null;
private ITemplate body = null;
[TemplateContainer(typeof(GenericContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate HeaderTemplate
{
get
{
return headers;
}
set
{
headers = value;
}
}
[TemplateContainer(typeof(GenericContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate BodyTemplate
{
get
{
return body;
}
set
{
body = value;
}
}
public string DivStyle
{
get { return divStyle; }
set { divStyle= value; }
}
public string NoDataMessage
{
get { return noDataMessage; }
set { noDataMessage = value; }
}
public string SpryDataSetName
{
get { return spryDataSetName; }
set { spryDataSetName = value; }
}
public bool CallCreatePaging
{
get { return callCreatePaging; }
set { callCreatePaging = value; }
}
void Page_Init()
{
if (headers != null)
{
GenericContainer container = new GenericContainer();
headers.InstantiateIn(container);
HeaderColumns.Controls.Add(container);
GenericContainer container2 = new GenericContainer();
body.InstantiateIn(container2);
BodyColumns.Controls.Add(container2);
}
}
public class GenericContainer : Control, INamingContainer
{
internal GenericContainer()
{
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
aspx
<spry:listview SpryDataSetName="dsOrders" CallCreatePaging="true" runat="server" ID="orderListView">
<HeaderTemplate>
<th> </th>
<th>SİPARİŞ TARİHİ</th>
<th style="text-align:right">GENEL TOPLAM</th>
<th style="text-align:right">KDV</th>
<th style="text-align:right">NET TOPLAM</th>
</HeaderTemplate>
</spry:listview>
[编辑]
我想在 mvc 3 razor 局部视图中做到这一点。
【问题讨论】:
标签: asp.net-mvc razor partial-views sections