In trying to get my brain around RenderPage v. Html.Partial v. Html.RenderPartial, I've been playing with some test files. I ran into some strange behavior: once RenderPage() is called, it seems like all subsequent calls to Html.RenderPartial() become no-ops. Why is one preventing the other?
Foo.cshtml:
<div>foo</div>
Bar.cshtml:
<div>bar</div>
Test1.cshtml:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
@{ Html.RenderPartial("Foo"); }
@RenderPage("Bar.cshtml")
</body>
</html>
Test2.cshtml:
// Test2.cshtml is identical to Test1.cshtml, except the two lines below
// ...
<body>
@RenderPage("Bar.cshtml") // this line used to be second
@{ Html.RenderPartial("Foo"); } // this line used to be first
</body>
Test1 behaves exactly as you'd expect:
foo
bar
However, Test2 never renders "foo"; it's as if my call to @{ Html.RenderPartial("Foo"); } never happens.
I realize this example is contrived - I'm not looking for ways to fix the issue. I'm trying to understand how RenderPage and Html.RenderPartial are related, and why they are interfering with each other.