I am currently unable to get @Html.Partial()
to render a view within a @section
.
Is this supported in ServiceStack? In my example code below, the first partial (outside of the @section
) does get rendered. Inside the @section
only the surrounding HTML gets rendered.
My folder structure looks like this:
MyLayout.cshtml looks like this:
@inherits ServiceStack.Razor.ViewPage<MyViewModelBase>
...
@RenderBody()
<div id="sidebar">
@RenderSection("sidebar")
</div>
MyView.cshtml contains this:
@inherits ServiceStack.Razor.ViewPage<MyViewModel>
@{
Layout = "MyLayout";
}
@Html.Partial("_MyPartialView")
@section sidebar {
<h2>Side Bar</h2>
@Html.Partial("_MyPartialView")
<p>Some other content</p>
}
The partial view contains nothing but plain HTML.
I reported the bug on Github a couple of days ago and @mythz commited a fix for the issue.
See my SO post: Service Stack 4.0.15: Razor Partial not outputted inside @section
The good news is the fix is available 4.0.16 (pre-release) via Myget (https://github.com/ServiceStack/ServiceStack/wiki/MyGet)
Here is the issue on Github:
https://github.com/ServiceStack/Issues/issues/60
Maybe you can do something like this?
@{ var myPartialView = Html.Partial("_MyPartialView"); }
@section sidebar {
<h2>Side Bar</h2>
@myPartialView
<p>Some other content</p>
}
since Html.Partial just returns a MvcHtmlString you can put it into a variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With