子ビューを想定します。
@Section Section1 {
@:Section1 Stuff
}
@Section Section2 {
@:Section2 Stuff
}
@Section ExtraSection {
@:Extra Section Stuff
}
Section1 と Section2 がそれぞれの場所に移動し、残りのすべてが統一された方法で処理されるように、マスター ビューをセットアップするにはどうすればよいですか? (たとえば @RenderAllOtherSections() のように)
@RenderSection("Section1")
@RenderSection("Section2")
@RenderBody()
@RenderAllOtherSections() // ExtraSection is rendered here. How?
更新:カミソリ ビュー Web ページのベース オブジェクトを調べたところ、以前の (呼び出し元の) ビューで定義されたセクションを含む辞書があることがわかりました。パラメータにありPreviousSectionWritersますが、これにはプライベートな get があります。また、このディクショナリは実際にはスタック内の 2 番目のアイテムですSectionWritersStackが、スタックにはプライベート get もあります。すでにレンダリングされたセクションは、「完了」として に保存されHashSet<string> _renderedSectionsます。これも非公開です。
要するに、私がアクセスする必要があるものは次のWebPageBaseとおりです。
public abstract class WebPageBase : WebPageRenderingBase
{
private HashSet<string> _renderedSections
Dictionary<string, SectionWriter> PreviousSectionWriters // private get, its the 2nd item in SectionWritersStack
Stack<Dictionary<string, SectionWriter>> SectionWritersStack // this would do too, but private get
}
問題は、これらのプロパティにアクセスできるようにするにはどうすればよいかということです。ヘルパー メソッドbool IsSectionDefined(string name)は、パブリックにアクセスできる唯一のものですが、あまり役に立ちません。