1

ASP.NET MVC にある @helper ユーティリティを使用して、次のヘルパーを作成しようとしています。アイデアは、パネルを作成し、ページからこのヘルパーを呼び出して、パネルのタイトルと本文を設定することです (レイアウトを使用できないため、同じページに複数のパネルを配置したい)。

ヘルパーは次のとおりです。

@helper PanelHelper(string title, string body){
    <fieldset class="fieldset-border-2">
        <legend style="display: none;">Edit</legend>
        <div style="display: table;">
            <div style="display: table-row;">
                <div class="panel-first-row" style="display: table-cell;">
                    <div style="border-bottom: 1px solid #cecece; padding-left: 5px; height: 25px;">
                        <div style="display: table; margin: 9px 0 9px 0;">
                            <div style="display: table-row;">
                                <div class="title" style="display: table-cell;">
                                    @title
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="edit-row-separator" style="display: table-row;">
            </div>
            <div style="display: table-row;">
                <div style="display: table-cell;">
                    @body
                </div>
            </div>
        </div>
    </fieldset>
}

そして、ここでこのヘルパーを呼び出す方法は次のとおりです。

@Helpers.PanelHelper("Customers")
{
    <div style="display: table; width: 100%;">
        <div style="display: table-row; width: 100%;">
           ................ HTML => Customer Fields ......................
        </div>
    </div>
}
4

1 に答える 1

0

あなたは本当にこのようにそれを呼び出す必要があります:

@{
   string body = "<div style=\"display: table; width: 100%;\">
        <div style=\"display: table-row; width: 100%;\">
           ................ HTML => Customer Fields ......................
        </div>
    </div>";
}


@PanelHelper("Customers", body)

詳細については、 http ://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-helper-syntax-within-razor.aspx をご覧ください。

于 2012-07-17T20:37:24.200 に答える