I am running Umbraco 6.0.7 and trying to make a partial view work in a template, but get the error
The view at '~/Views/Partials/kb.cshtml' must derive from WebViewPage, or WebViewPage.
I am unsure how to fix this - so any help is appreciated.
The template:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "Site.cshtml";
}
<div>
@Html.Partial("kb")
</div>
The Partial view (kb.cshtml):
@inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var parent = Model.AncestorOrSelf(2);
if (parent != null) {
traverse(parent,2,3);
}
}
@helper traverse(dynamic parent,int startLevel,int finishLevel) {
<ul>
foreach (var item in parent.Children.Where("umbracoNaviHide!=true")) {
var selected = (Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "");
<li >
<a href="item.Url">item.Name</a>
if (selected !="" && item.Level <= 3) {
traverse(item,2,3)
}
</li>
}
</ul>
}
Remove the top two lines from kb.cshtml:
@inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>
@inherits umbraco.MacroEngines.DynamicNodeContext
and replace them with:
@inherits UmbracoTemplatePage
This is no different to implementing a standard MVC partial that inherits its model from the parent view.
There is a lot of documentation at our.umbraco.org that I seriously suggest you read through as this will help massively with things like this.