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
    Apr 21, 2015 @ 21:48
    Nicolai
    0

    Trying to fix this razor view

    Hey guys, 

    Im having some trouble getting this code to work. Can anyone see why its not working?

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var sliderItems = Umbraco.Content(5021);
        var magazineLevel = CurrentPage.DescendantsOrSelf("Magazine").OrderBy("magazineDate desc, magazineDate");
        var latestMagazine = magazineLevel.Take(1);
    
    <div class="container-fluid">
        <div class="row-fluid">   
            <div class="carousel slide" id="myCarousel" data-ride="carousel">
                <ol class="carousel-indicators">
                    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                    <li data-target="#myCarousel" data-slide-to="1"></li>
                </ol>
    
                <div class="carousel-inner">
                    <ul class="thumbnails">       
    
    
                @foreach (var item in sliderItems.Children.OrderBy("Id desc")) {
                    @if (item.HasValue("frontpageSliderItemArticleOneId")) {
                        var article = Umbraco.Content(item.frontpageSliderItemArticleOneId);
                        var articleImage = Umbraco.Media(article.homepageArticleImage);
    
                        <li>
                            <div class="thumbnail" id="magazineSliderSmall">
                                <div class="articleTitle">
                                    <span class="title"><p><a href="@article.Url">@article.homepageArticleTitle</a></p></span>
                                </div>
                                <div class="artPic">
                                    <a href="@article.Url">
                                        <img style="height: 111px; width: 311px;" src="@articleImage.umbracoFile" alt="">
                                    </a>
                                </div>
                            </div>
                        </li>
                    }
    
                    @if (item.HasValue("frontpageSliderItemArticleTwoId")) {
                        var article = Umbraco.Content(item.frontpageSliderItemArticleOneId);
                        var articleImage = Umbraco.Media(article.homepageArticleImage);
    
                        <li>
                            <div class="thumbnail" id="magazineSliderSmallMid">
                                <div class="articleTitle">
                                    <span class="title"><p><a href="@article.Url">@article.homepageArticleTitle</a></p></span>
                                </div>
                                <div class="artPic">
                                    <a href="@article.Url">
                                        <img style="height: 111px; width: 311px;" src="@articleImage.umbracoFile" alt="">
                                    </a>
                                </div>
                            </div>
                        </li>
                    }
    
                    @if (item.HasValue("frontpageSliderItemArticleThreeId")) {
                        var article = Umbraco.Content(item.frontpageSliderItemArticleOneId);
                        var articleImage = Umbraco.Media(article.homepageArticleImage);
    
                        <li>
                            <div class="thumbnail" id="magazineSliderSmall">
                                <div class="articleTitle">
                                    <span class="title"><p><a href="@article.Url">@article.homepageArticleTitle</a></p></span>
                                </div>
                                <div class="artPic">
                                    <a href="@article.Url">
                                        <img style="height: 111px; width: 311px;" src="@articleImage.umbracoFile" alt="">
                                    </a>
                                </div>
                            </div>
                        </li>
                    }
                }  
                    </div>
                </ul>
            </div>
    
        <a data-slide="prev" href="#myCarousel" class="left carousel-control">‹</a>
        <a data-slide="next" href="#myCarousel" class="right carousel-control">›</a>
    
        </div>
      </div>
    </div>
    }
    
    Im getting the fallowing error: Error loading Partial View script
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 21, 2015 @ 21:52
    Jan Skovgaard
    0

    Hi Nicolai

    Could you please check the /App_Data/Logs file and see if anything marked with ERROR provides some more useful information about the error?

    And does Visual Studio provide any hints about the issue if you're a VS guy?

    /Jan

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 21, 2015 @ 22:09
    Dennis Aaen
    100

    Hi Nicolai,

    I have looked into your code the only thing that I think that´s wrong with your code is that you have the @ in front of your if statments. You are in a foreach loop, so the Razor engine is started, so to say.

    So try this snippet of code and see if it works for you.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var sliderItems = Umbraco.Content(5021);
        var magazineLevel = CurrentPage.DescendantsOrSelf("Magazine").OrderBy("magazineDate desc, magazineDate");
        var latestMagazine = magazineLevel.Take(1);

    <div class="container-fluid">
        <div class="row-fluid">
            <div class="carousel slide" id="myCarousel" data-ride="carousel">
                <ol class="carousel-indicators">
                    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                    <li data-target="#myCarousel" data-slide-to="1"></li>
                </ol>
                <div class="carousel-inner">
                    <ul class="thumbnails">
                        @foreach (var item in sliderItems.Children.OrderBy("Id desc")) {
                            if (item.HasValue("frontpageSliderItemArticleOneId")) {
                                 var article = Umbraco.Content(item.frontpageSliderItemArticleOneId);
                                var articleImage = Umbraco.Media(article.homepageArticleImage);
                               
                                <li>
                                    <div class="thumbnail" id="magazineSliderSmall">
                                        <div class="articleTitle">
                                            <span class="title"><p><a href="@article.Url">@article.homepageArticleTitle</a></p></span>
                                        </div>
                                        <div class="artPic">
                                            <a href="@article.Url">
                                                <img style="height: 111px; width: 311px;" src="@articleImage.umbracoFile" alt="">
                                            </a>
                                        </div>
                                    </div>
                                </li>
                            }
                            if (item.HasValue("frontpageSliderItemArticleTwoId")) {
                                 var article = Umbraco.Content(item.frontpageSliderItemArticleOneId);
                                var articleImage = Umbraco.Media(article.homepageArticleImage);

                                <li>
                                    <div class="thumbnail" id="magazineSliderSmallMid">
                                        <div class="articleTitle">
                                            <span class="title"><p><a href="@article.Url">@article.homepageArticleTitle</a></p></span>
                                        </div>
                                        <div class="artPic">
                                            <a href="@article.Url">
                                                <img style="height: 111px; width: 311px;" src="@articleImage.umbracoFile" alt="">
                                            </a>
                                        </div>
                                    </div>
                                </li>
                            }
                            if (item.HasValue("frontpageSliderItemArticleThreeId")) {
                                var article = Umbraco.Content(item.frontpageSliderItemArticleOneId);
                                var articleImage = Umbraco.Media(article.homepageArticleImage);

                                <li>
                                    <div class="thumbnail" id="magazineSliderSmall">
                                        <div class="articleTitle">
                                            <span class="title"><p><a href="@article.Url">@article.homepageArticleTitle</a></p></span>
                                        </div>
                                        <div class="artPic">
                                            <a href="@article.Url">
                                                <img style="height: 111px; width: 311px;" src="@articleImage.umbracoFile" alt="">
                                            </a>
                                        </div>
                                    </div>
                                </li>
                            }
                        }
                    </ul>
                </div>
       

                <a data-slide="prev" href="#myCarousel" class="left carousel-control">‹</a>
                <a data-slide="next" href="#myCarousel" class="right carousel-control">›</a>
            </div>
         </div>
    </div>
    }

    /Dennis

  • Nicolai 48 posts 201 karma points
    Apr 21, 2015 @ 23:13
    Nicolai
    0

    You're right Dennis. I totally blanked out on that one :) Thanks alot!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 22, 2015 @ 07:13
    Jan Skovgaard
    0

    Hi Nicolai

    Good it got solved - As mentiond in my initial comment you can always check the trace-log to get some more useful descriptions of the error messages so you may be able to figure it out next time by having a look :)

    Have a nice day.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft