Copied to clipboard

Flag this post as spam?

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


  • Ritzin 3 posts 54 karma points
    Dec 22, 2014 @ 07:01
    Ritzin
    0

    Please help in converting code to Partial View

    Friends,

    Greetings!! I'm an absolute newbie trying to learn Umbraco and MVC in general.Currently I'm using version 7.2 and trying to make an image gallery from Warren's Razor Recipe series. I'm trying to convert the legacy Razor code to partial view macro but end up nowhere. Can anyone help me with this please?

    The one below is Mr. Warren's original code

    <div id="grid">

        @{

            foreach (var gallery in Model.Children)

            {

                if (gallery.HasValue("galleryImage"))

                {

                    var MediaGalleryFolder = Library.MediaById(gallery.galleryImage);

                   var noPhotos = MediaGalleryFolder.Children.Count();

     

                    //Get the first image in the folder

                    var imageNode = MediaGalleryFolder.Children.First();

                    var imageURL = imageNode.umbracoFile;

     

                    <article>

                        <a href="@gallery.Url">

                            <!-- Use ImageGen querystring to automatically generate a thumbnail & setup fallback image -->

                            <img src="/ImageGen.ashx?image=@imageURL&height=173&width=173&crop=resize&align=center&altImage=/img/no-image.png" alt="@gallery.Name"/>

                            <div>

                                <h4>

                                    <!-- Display page name & format the price to £150,000.00 -->

                                    @gallery.Name<br />

                                    @noPhotos photos

                                </h4>

                            </div>                            

                        </a>

                    </article>            

                }

            }

        }

    </div>

  • Keith Hubbard 174 posts 402 karma points
    Dec 22, 2014 @ 07:22
  • Keith Hubbard 174 posts 402 karma points
    Dec 22, 2014 @ 07:27
  • Ritzin 3 posts 54 karma points
    Dec 22, 2014 @ 07:30
    Ritzin
    0

    Thank you Keith for the quick help. Really appreciate that. Let me  go through those posts...

     

  • Keith Hubbard 174 posts 402 karma points
    Dec 22, 2014 @ 07:33
  • Ritzin 3 posts 54 karma points
    Dec 22, 2014 @ 08:14
    Ritzin
    101

    Keith, this worked for me

     

    <div id="grid">

        @{

            foreach (var gallery in CurrentPage.Children)

            {

                if (gallery.HasValue("galleryImage"))

                {

                    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;

                          <article>

                        <a href="@gallery.Url">

                            <!-- Use ImageGen querystring to automatically generate a thumbnail & setup fallback image -->

                            <img src="/ImageGen.ashx?image=@imageURL&height=173&width=173&crop=resize&align=center&altImage=/img/no-image.png" alt="@gallery.Name"/>

                            <div>

                                <h4>

                                    <!-- Display page name & format the price to £150,000.00 -->

                                    @gallery.Name<br />

                                    @noPhotos photos

                                </h4>

                            </div>                            

                        </a>

                    </article>            

                }

            }

        }

    </div>

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies