Question

J'ai défini une section en vue partielle et je souhaite spécifier le contenu de la section à partir de la vue. Mais je ne peux pas comprendre un moyen.Dans les contrôles des utilisateurs ASP.NET, nous pouvons définir ASP: les espaces réservés et Spécifiez le contenu à partir d'ASPX où réside le contrôle des utilisateurs.Je serai heureux de toute suggestion.

merci

[modifier] Voici le contrôle de l'utilisateur ASP.NET et je veux le convertir en Vue partielle de Razor

Contrôle utilisateur:

<%@ 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>

Code de contrôle utilisateur:

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>

[modifier]

Je veux faire exactement cela dans la vue partielle de MVC 3 Razor.

Était-ce utile?

La solution

Templated Razor Delegates seem to be what you're after. They essentially let your helpers take the template (your delegate) as an argument you pass in from the view. This way it is the caller (your view) that controls the way information is rendered, not the helper, thus giving you more flexibility.

Autres conseils

You should take a Func<object, HelperResult> as a parameter to the partial view.
In the parent view, you can pass HTML like @<div>...</div> as the parameter.

In the partial view, you can call the delegate with any parameter to render the HTML.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top