微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net-mvc – Mvc 3 Razor:使用部分部分视图?

我在局部视图中定义了一个部分,我想从视图中指定部分的内容.
但我无法想像出来.在asp.net用户控件中,我们可以定义asp:占位符和
指定用户控件所在的aspx中的内容.我会很乐意提出任何建议.

谢谢

[编辑]
这是asp.net用户控件,我想将其转换为剃刀部分视图

用户控制:

<%@ 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>&nbsp;</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剃刀部分视图中做这个.

解决方法

Templated Razor Delegates似乎是你以后的事情.他们基本上让你的帮助者将模板(你的代表)作为你从视图传入的参数.这样,调用者(您的视图)控制信息呈现的方式,而不是帮助者,从而为您提供更多的灵活性.

原文地址:https://www.jb51.cc/aspnet/246075.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐