Copied to clipboard

Flag this post as spam?

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


  • Nicolai 48 posts 201 karma points
    Mar 13, 2015 @ 10:27
    Nicolai
    0

    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:

    @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"))
          {
           
    •   
             

               

                 
       

               

                  @item.homepageArticleTitle

                  af @item.homepageArticleByline

                 

      @item.homepageArticleTeaser


                 
      @item.homepageArticleDate.ToShortDateString()
       

    •     }else 
          {
           
    •   
             

                   

                      @item.homepageArticleTitle

                      af @item.homepageArticleByline

                     

      @item.homepageArticleTeaser


                     
      @item.homepageArticleDate.ToShortDateString()

    •         }
          }


          @for (int p = 1; p < totalPages + 1; p++)
          {
              string selected = (p == page) ? "selected" : String.Empty;
             
    • @p
    •  
          }
            
    This script is not working apparently. Can anyone see why?
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Mar 13, 2015 @ 10:56
    Dave Woestenborghs
    0

    What error do you get ?

    Can you hit place a breakpoint in Visual Studio and see if it get's hit.

    Dave

  • Nicolai 48 posts 201 karma points
    Mar 13, 2015 @ 11:13
    Nicolai
    0

    Error loading Partial View script (file: ~/Views/MacroPartials/ArticleListPartial.cshtml)

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Mar 13, 2015 @ 11:18
    Dave Woestenborghs
    0

    How do you call your macro from your template ?

    Dave

  • Nicolai 48 posts 201 karma points
    Mar 13, 2015 @ 11:21
    Nicolai
    0

    <umbraco:Macro Alias="Name" runat="server"></umbraco:Macro>

  • Nicolai 48 posts 201 karma points
    Mar 13, 2015 @ 11:23
    Nicolai
    0

    So Template:

    <umbraco:Macro Alias="Name" runat="server"></umbraco:Macro>

    Macro pointing to partial view macro

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Mar 13, 2015 @ 11:25
    Dave Woestenborghs
    0

    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

  • Nicolai 48 posts 201 karma points
    Mar 13, 2015 @ 11:41
    Nicolai
    0

    I actually got it to work for some of my macro scripts. So I guess it is workable :)

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Mar 13, 2015 @ 11:53
    Dave Woestenborghs
    0

    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

  • Nicolai 48 posts 201 karma points
    Mar 13, 2015 @ 13:06
    Nicolai
    0

    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; 

      }

Please Sign in or register to post replies

Write your reply to:

Draft