note: I’m using a theme I bought from uskinned.
when I navigate to a page (“pageA”)(id: 1183) with document type DocTypeA that has the following template:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = “master.cshtml”;
}
.
.
.
and master.cshtml is
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = null;
}
.
.
@Html.Partial(“section/SEOPageHead”, @Model.Content) ← Line B
.
.
and SEOPageHead.cshtml is
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
IPublishedContent homeNode = Model.Content.AncestorOrSelf(1); ← Line C
.
.
there are no errors.
If I hover over Model in line B or C above in debug mode, I see both Model.Content and Model.CurrentCulture.
I then followed Custom MVC routing in Umbraco - Shazwazza
to implement the following custom route
localhost/cars/views/3
using the class..
public class CarChartsController : Umbraco.Web.Mvc.PluginController
{
public CarChartsController ()
: this(UmbracoContext.Current)
{
}
public CarChartsController (UmbracoContext umbracoContext)
: base(umbracoContext)
{
}
public ActionResult Views(string id)
{
var y = umbracoContext.ContentCache.GetById(1183); //this is the same doc id as pageA/DocTypeA from the very top
return View("~/Views/views.cshtml", CreateRenderModel(y));
}
private RenderModel CreateRenderModel(IPublishedContent content)
{
var model = new RenderModel(content, CultureInfo.CurrentUICulture);
//add an umbraco data token so the umbraco view engine executes
RouteData.DataTokens["umbraco"] = model;
//new UmbracoHelper()
return model;
}
}
views.cshtml is
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = “USNMaster.cshtml”;
}
.
.
.
now if navigate to localhost/cars/views/3, I get a system.nullreferenceexception error during debug.
now if I change Line B to
@Html.Partial(“section/SEOPageHead”, @Model) // @Model.Content replaced by @Model
everything works when I navigate to the custom route localhost/cars/views/3.
Any ideas why the partial view when going via custrom route didn’t work originally but did work when going through the normal umbraco route?
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/75619-need-help-understanding-why-the-partial-view-error-exists-in-custom-route