It is possible to solve this with razor helpers. It's kinda elegantly-hacky™ but it did the job for me.
So in a parent view you define a helper:
@helper HtmlYouWantRenderedInAPartialView()
{
<blink>Attention!</blink>
}
Then when you render partial, you pass this helper to it
@Html.Partial("somePartial", new ViewDataDictionary { { "OptionalSection1", (Func<HelperResult>)(HtmlYouWantRenderedInAPartialView) } })
Then inside a partial view you call this helper like so
<div>@ViewData.RenderHelper("OptionalSection1")</div>
Finally you need to have this extension method to simplify the "calling" part
public static HelperResult RenderHelper(this ViewDataDictionary<dynamic> viewDataDictionary, string helperName)
{
Func<HelperResult> helper = viewDataDictionary[helperName] as Func<HelperResult>;
if (helper != null)
{
return helper();
}
return null;
}
So the whole point is to pass a delegate of this helper and then when the child view calls it, the contents get rendered where you want them.
The end result of a child view would look like this
<div><blink>Attention!</blink></div>