Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • JSuh 6 posts 108 karma points
    Mar 05, 2016 @ 05:06
    JSuh
    0

    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..

    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?

  • Marc Love (uSkinned.net) 447 posts 1789 karma points
    Mar 07, 2016 @ 15:45
    Marc Love (uSkinned.net)
    0

    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.

  • JSuh 6 posts 108 karma points
    Jun 12, 2016 @ 04:55
    JSuh
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft