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.
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.
@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.
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);
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 :)
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.
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
It is pretty much same as in the guide but here is the code anyways
And here is the PartialView Macro listArticles
UPDATE: I got the simple hello world macro to run ok.
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
And the check for results would look like this
Hopefully this gets you a bit closer to an answer
Paul
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 :)
is working on a reply...