I\'m passing some data to a View from my controller, which I wish to display inside a partial view inside that View (don\'t ask, it\'s complicated). I know I probably should
Is this behaviour intended like that in WPF where child controls inherit the data context of their parent View?
Yes.
I see you are not currently passing any model to the Would it work to just inherit the layouts, and then not need to use the partial at all?
If you want to keep using it like you are, maybe just be more explicit about it, and pass the current model to the partial.
@Html.Partial("_IndexPartial", Model)
If you look at the source for Html.Partial(view):
public static MvcHtmlString Partial(this HtmlHelper htmlHelper, string partialViewName)
{
return Partial(htmlHelper, partialViewName, null /* model */, htmlHelper.ViewData);
}
It is passing the model via htmlHelper.ViewData, you can access the model in the same way in your view with @{ViewData.Model}, but this is NOT a good practice.