Im trying to convert my macro script based webpages to partial view macros. If anyone have good some ideas to where I can find information about this subject, please post it.
Script:
@using umbraco.MacroEngines; @inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var node = Umbraco.Content(12303); var articles = node.Children; int pageSize; // How many items per page int page; // The page we are viewing if (!int.TryParse(Parameter.PageSize, out pageSize)) { pageSize = 10; } if (!int.TryParse(Request.QueryString["page"], out page)) { page = 1; } int totalArticles = articles.Count(); int totalPages = (int)Math.Ceiling((double)totalArticles / (double)pageSize); if (page > totalPages) { page = totalPages; } else if (page < 1) { page = 1; } }
@foreach (var item in articles.OrderBy("homepageArticleDate desc, homepageArticleDate").Skip((page - 1) * pageSize).Take(pageSize)) { if (item.HasValue("homepageArticleImage")) {
Seeing this code I assume that you are using Webforms for your template. I don't think it is possible to have MVC macro partials view for when running in Webforms mode. But maybe I can be wrong.
Why is this Dynamic MVC view not loading?
Im trying to convert my macro script based webpages to partial view macros. If anyone have good some ideas to where I can find information about this subject, please post it.
Script:
@foreach (var item in articles.OrderBy("homepageArticleDate desc, homepageArticleDate").Skip((page - 1) * pageSize).Take(pageSize))
{
if (item.HasValue("homepageArticleImage"))
{
@item.homepageArticleTitle
af @item.homepageArticleByline
@item.homepageArticleTeaser
}else
{
@item.homepageArticleTitle
af @item.homepageArticleByline
@item.homepageArticleTeaser
}
}
@for (int p = 1; p < totalPages + 1; p++)
{
string selected = (p == page) ? "selected" : String.Empty;
}
What error do you get ?
Can you hit place a breakpoint in Visual Studio and see if it get's hit.
Dave
Error loading Partial View script (file: ~/Views/MacroPartials/ArticleListPartial.cshtml)
How do you call your macro from your template ?
Dave
<umbraco:Macro Alias="Name" runat="server"></umbraco:Macro>
So Template:
<umbraco:Macro Alias="Name" runat="server"></umbraco:Macro>
Macro pointing to partial view macro
Seeing this code I assume that you are using Webforms for your template. I don't think it is possible to have MVC macro partials view for when running in Webforms mode. But maybe I can be wrong.
Dave
I actually got it to work for some of my macro scripts. So I guess it is workable :)
I guess you have a error in you code then that I can not find at the moment.
Maybe you can start by commenting out all code. And re enable line by line to see what line is giving you a error.
Dave
So I have found out that its all about how I calculate the page size.
Script:
if (page > totalPages) {
page = totalPages;
} else if (page < 1) {
page = 1;
}
is working on a reply...