Copied to clipboard

Flag this post as spam?

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


  • Nick 95 posts 492 karma points
    Feb 13, 2017 @ 23:03
    Nick
    0

    Helpers does not exist in the namespace 'Microsoft.Web

    Hi,

    I am having trouble upgrading an existing Umbraco site v7.2 to v7.5, in particular, a gallery page which renders different folders from the media library of images here is the code:

       @{
    //Check the currentpage has a value in the property 'photos'
    if (Model.HasValue("photos"))
    {
        var MediaFolder = Library.MediaById(Model.photos);
    
            <ul class="clearing-thumbs" data-clearing>
                @foreach (var photo in MediaFolder.Children)
                    {
                        <li>
                            <a class="th" href="/[email protected]" rel="gallery"><img src="/[email protected]&width=146&height=112&constrain=true&crop=resize&align=center&altImage=/img/no-image.png" alt="@photo.Name"/></a>
    
                        </li>
                    }
            </ul>
    }
    

    }

    The page errors with this CS0234: The type or namespace name 'Helpers' does not exist in the namespace 'Microsoft.Web' (are you missing an assembly reference?)

    Now I've searched a few forums which suggest adding back in the Microst.Web.Helpers dll file. but all this does is make the whole site error with this:

    Attempt by security transparent method

    'Microsoft.Web.Helpers.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)' failed.

    I am well and truly stuck if anybody could help me would be much appreciated.

    Kind Regards

    Nick

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Feb 14, 2017 @ 07:28
    Dave Woestenborghs
    0

    Hi Nick,

    Don't see any code that should need this library. Is it only this view or are there other views that have this issue as well.

    Have you tried removing the code from the view or and adding pieces one by one.

    This usually helps me detected the offending line when I don't have any debug tools available.

    Dave

  • Nick 95 posts 492 karma points
    Feb 14, 2017 @ 09:28
    Nick
    0

    Many thanks Dave,

    This is the only piece of code that breaks the site here http://dev.greenovalgarage.co.uk/gallery/ , I've tried removing the code bit by bit but no joy, if I remove the code altogether the page renders but without the gallery images.

    Here is the gallery code, although the main image isn't being rendered, which could be part of the problem:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{ foreach (var gallery in CurrentPage.Children) { if (gallery.HasValue("photos")) { var MediaGalleryFolder = Umbraco.Media((int)gallery.galleryImage); var noPhotos = MediaGalleryFolder.Children.Count(); //Get the first image in the folder var imageNode = MediaGalleryFolder.Children.First(); var imageURL = imageNode.umbracoFile; } } }
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Feb 14, 2017 @ 11:11
    Dave Woestenborghs
    0

    Hi Nick,

    I rewrote your marcro a little bit to use strongly typed syntax.

    Can you check if this works for you :

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @foreach (var gallery in Model.Content.Children) 
    {
        if (gallery.HasValue("photos"))
        {
            var MediaGalleryFolder =  Umbraco.TypedMedia((gallery.GetPropertyValue<int>("photos"));
    
            if(MediaGalleryFolder != null) 
            {
                var images = MediaGalleryFolder.Children;
    
                if(images.Any()) 
                {
                    var imageNode = images.First();
                    var imageUrl = imageNode.GetPropertyValue<string>("umbracoFile");
    
                    <div class="large-3 medium-4 columns">
                        <div class="panel listing radius ">
                            <a href="@gallery.Url">
                                <!-- Use ImageGen querystring to  automatically generate a thumbnail & setup fallback image -->
                                    <img src="/ImageGen.ashx?image=@imageURL&height=200&width=200&crop=resize&align=center&altImage=/img/no-image.png" alt="@imageNode.Name"/>
                                        <div>
                                            <h4>@imageNode.Name<br />@images.Count() photos</h4>
                                        </div>                            
                            </a>
                        </div>
                    </div> 
                }
            }       
        }
    }
    

    Dave

  • Nick 95 posts 492 karma points
    Feb 14, 2017 @ 12:03
    Nick
    0

    Thanks Dave,

    Just tried it, seems to have a missing { bracket.

    enter image description here

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Feb 14, 2017 @ 12:17
    Dave Woestenborghs
    100

    Hi Nick,

    Were you able to fix it ?

    If not try this one

    @foreach (var gallery in Model.Children)
    {
        if (gallery.HasValue("photos"))
        {
            var MediaGalleryFolder = Umbraco.TypedMedia(gallery.GetPropertyValue<int>("photos"));
    
            if (MediaGalleryFolder != null)
            {
                var images = MediaGalleryFolder.Children;
    
                if (images.Any())
                {
                    var imageNode = images.First();
                    var imageUrl = imageNode.GetPropertyValue<string>
                        ("umbracoFile");
    
                    <div class="large-3 medium-4 columns">
                        <div class="panel listing radius ">
                            <a href="@gallery.Url">
                                <!-- Use ImageGen querystring to  automatically generate a thumbnail & setup fallback image -->
                                <img src="/ImageGen.ashx?image=@imageUrl&height=200&width=200&crop=resize&align=center&altImage=/img/no-image.png" alt="@imageNode.Name" />
                                <div>
                                    <h4>@imageNode.Name<br />@images.Count() photos</h4>
                                </div>
                            </a>
                        </div>
                    </div>
                }
            }
        }
    }
    

    Dave

  • Nick 95 posts 492 karma points
    Feb 14, 2017 @ 12:50
    Nick
    0

    Thanks for your time on this Dave, hope I am not ruining your day. Used the code above but get a different error message now:

    enter image description here

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Feb 14, 2017 @ 13:20
    Dave Woestenborghs
    0

    Ah Nick,

    My mistake. Should be Model.Content.Children

    And no, you are not ruining my day

    Dave

  • Nick 95 posts 492 karma points
    Feb 14, 2017 @ 14:03
    Nick
    0

    Thank's Dave that did the trick, http://dev.greenovalgarage.co.uk/gallery Although the second page still errors but with something different now:

    CS1928: 'Umbraco.Web.Models.PartialViewMacroModel' does not contain a definition for 'HasValue' and the best extension method overload 'Umbraco.Web.PublishedContentExtensions.HasValue(Umbraco.Core.Models.IPublishedContent, string)' has some invalid arguments

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Feb 14, 2017 @ 14:45
    Dave Woestenborghs
    0

    Is that the same view or another one ?

    Dave

  • Nick 95 posts 492 karma points
    Feb 14, 2017 @ 14:50
    Nick
    0

    It's a different view, but the original script was in the initial post above. But it does inherit from the previous one, if that makes sense.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Feb 15, 2017 @ 07:24
    Dave Woestenborghs
    0

    Hi Nick,

    Can you post the code of this script ? Let's see if I can have a go at it.

    Dave

  • Nick 95 posts 492 karma points
    Feb 15, 2017 @ 13:22
    Nick
    0

    Hi Dave, Thanks for your patience on this. So the first bit of code yesterday essential chooses a media folder with images in and displays the first image, and this works great now thanks to you, http://dev.greenovalgarage.co.uk/gallery/ and click on the gallery images.

    The second piece of good basically displays the remaining images within that folder on a separate page this is the code:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage           
    @{
    //Check the currentpage has a value in the property 'photos'
    if (Model.HasValue("photos"))
    {
        var MediaFolder = Model.MediaById(Model.photos);
    
            <ul class="clearing-thumbs" data-clearing>
                @foreach (var photo in MediaFolder.Children)
                    {
                        <li>
                            <a class="th" href="/ImageGen.ashx?    [email protected]" rel="gallery"><img src="/[email protected]&width=146&height=112&constrain=true&crop=resize&align=center&altImage=/img/no-image.png" alt="@photo.Name"/></a>
                        </li>
                    }
            </ul>
      }
    }
    
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Feb 15, 2017 @ 13:56
    Dave Woestenborghs
    0

    Hi Nick,

    I think this should do the trick :

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        //Check the currentpage has a value in the property 'photos'
        if (Model.Content.HasValue("photos"))
        {
            var MediaFolder = this.Umbraco.TypedMedia(Model.Content.GetPropertyValue<int>("photos"));
    
            <ul class="clearing-thumbs" data-clearing>
                @foreach (var photo in MediaFolder.Children)
                {
                    var url = photo.GetPropertyValue<string>("umbracoFile");
                    <li>
                        <a class="th" href="/ImageGen.ashx?    image=@url" rel="gallery"><img src="/ImageGen.ashx?image=@url&width=146&height=112&constrain=true&crop=resize&align=center&altImage=/img/no-image.png" alt="@photo.Name" /></a>
                    </li>
                }
            </ul>
        }
    }
    

    Dave

  • Nick 95 posts 492 karma points
    Feb 15, 2017 @ 14:15
    Nick
    0

    Brilliant Dave, works a treat, thanks very much for your time and effort on this.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Feb 15, 2017 @ 14:28
    Dave Woestenborghs
    0

    No problem... we were all new here once. And it's nice to get help.

Please Sign in or register to post replies

Write your reply to:

Draft