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.
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;
}
}
need help understanding why the partial view error exists in custom route...........................
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 http://shazwazza.com/post/Custom-MVC-routing-in-Umbraco to implement the following custom route localhost/cars/views/3
using the class..
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?
Partial views in Umbraco by default inherit from Umbraco.Web.Mvc.UmbracoTemplatePage
To get at IPublished content in this scenario you use @Model.Content
I think the change you have made changes your Partial view to expect IPublishedContent which means you then get at the content directly using @Model.
Marc,
I took a long break from this project. Anyways, I was able to solve this problem by following http://shazwazza.com/post/Custom-MVC-routes-within-the-Umbraco-pipeline
and simply using code based off his articulate project.
is working on a reply...