Copied to clipboard

Flag this post as spam?

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


  • iamadnan 3 posts 83 karma points
    Apr 06, 2018 @ 13:51
    iamadnan
    0

    Can't get the PartialView Macro listArticles to run

    Hi, I am Umbraco/7.8.1 beginner, trying to follow the on site guide on creating "Article Parent and Article Items" https://our.umbraco.org/documentation/tutorials/creating-basic-site/Articles-Parent-and-Article-Items. I created the macro as the guide says but somehow I can't seem to get it to run, tried the forum and suggestions but the problem is still there. I tried a simple macro with just "hello world" after header and same result. Can't think of anything wrong I did, as I have been following the online guides.

    [NullReferenceException: Object reference not set to an instance of an object.]
       System.Web.WebPages.WebPageBase.CreateInstanceFromVirtualPath(String virtualPath, IVirtualPathFactory virtualPathFactory) +54
       umbraco.MacroEngines.RazorMacroEngine.CompileAndInstantiate(String virtualPath) +38
       umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) +317
       umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage) +498
       umbraco.macro.loadMacroScript(MacroModel macro) +181
       umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId) +4413
       Umbraco.Web.UmbracoComponentRenderer.RenderMacro(macro m, IDictionary`2 parameters, page umbracoPage) +472
       ASP._Page_Views_ArticlesMain_cshtml.Execute() in e:\Source\UmbracoCms.7.8.1\Views\ArticlesMain.cshtml:11
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +252
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +148
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +107
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +194
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +375
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +88
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +776
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +776
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +776
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
       System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
       System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
       System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +43
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +393
       System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128
    
  • Paul Tilsed 26 posts 179 karma points c-trib
    Apr 06, 2018 @ 14:10
    Paul Tilsed
    0

    Hi,

    Would you be able to post the code you have in the ArticlesMain.cshtml view file so we can see the source line of the error. It might also be useful to see the contents of the Macro file you are calling as well just in case the error is happening in there.

    Double check the MVC Partial view is set correctly on the Macro as well, it should be the path to the .cshtml file you have in the MacroPartials folder.

    Is the rest of the site running ok?

    Paul

  • iamadnan 3 posts 83 karma points
    Apr 06, 2018 @ 14:23
    iamadnan
    0

    It is pretty much same as in the guide but here is the code anyways

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.ArticlesMain>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "Master.cshtml";
    }
    <div id="main-container">
        <div id="main" class="wrapper clearfix">
            <section>
                <h2>@Umbraco.Field("articlesTitle")</h2>
                @Umbraco.Field("articlesBodyText")
                @Umbraco.RenderMacro("listArticles")
            </section>  
        </div> <!-- #main -->
    </div> <!-- #main-container -->
    

    And here is the PartialView Macro listArticles

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Umbraco.Web
    
    
    @*
        This snippet makes a list of links to the of children of the current page using an unordered HTML list.
    
        How it works:
        - It uses the Children method to get all child pages
        - It then uses the OrderByDescending() method, which takes the property to sort. In this case the page's creation date.
        - It then generates links so the visitor can go to each page
    *@
    
    @{ var selection = Model.Content.Children.Where(x => x.IsVisible()).OrderByDescending(x => x.CreateDate).ToArray(); }
    
    @if (selection.Length > 0)
    {
        <ul>
            @foreach (var item in selection)
            {
                <li><a href="@item.Url">@item.Name</a></li>
            }
        </ul>
    }
    

    UPDATE: I got the simple hello world macro to run ok.

  • Paul Tilsed 26 posts 179 karma points c-trib
    Apr 06, 2018 @ 15:09
    Paul Tilsed
    100

    Hi,

    As you say the code looks fine and when I try it with a clean install of Umbraco it works fine for me as well.

    I would suggest putting a break point on line 14 of the macro and then stepping over to see the results of the selection query and checking if anything is returned.

    It might also be useful to change the query to just retrun the results without calling ToArray() as its possible you have no results to turn to an array.

    So the query would look like this

    var selection = Model.Content.Children.Where(x => x.IsVisible()).OrderByDescending(x => x.CreateDate);
    

    And the check for results would look like this

    @if (selection != null && selection.Any())
    

    Hopefully this gets you a bit closer to an answer

    Paul

  • iamadnan 3 posts 83 karma points
    Apr 07, 2018 @ 08:22
    iamadnan
    0

    Thanks Paul Tilsed for your time and advice. I tried your code but it wasn't working either so I went for the clean install option, as it has to work the second time :) May be it was something I messed up in the installation (IIS) or may be I missed something in the instructions while doing something differently to suit my needs. Anyways for future reference to beginners 'Please follow the installation instructions carefully' at least for the first time and do not mess with the process outlined in the tutorials. Though I noticed that the tutorials have not been updated in accordance with changes in the latest release but otherwise it is pretty much straight forward. I spent more time in finding the issue but as Paul advised a clean installation took lesser time so you know what to do when you are stuck somewhere and it is taking a lot of time :)

Please Sign in or register to post replies

Write your reply to:

Draft