Copied to clipboard

Flag this post as spam?

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


  • Keith R Hubbard 175 posts 403 karma points
    Aug 24, 2013 @ 16:59
    Keith R Hubbard
    0

    Querying Specific nodes and children of specific nodes in MVC for homepage

    I have tryid so many things to get this to work.  I should not be this hard to get content of a specific node and display it on the home page.  In webforms i could use NodeById and get the item of any children.  What is the solution for MVC?  Below is how i use to do it in webforms. 

    This is how I use to get nodes and list them on other pages before MVC. 

     

    @{
        // Get all child items based on the document type 'Services' and group them is 4
        <div class="FeaturedProduct">
        @foreach (var group in @Model.NodeById(2045).Children.InGroupsOf(3))
        {
           foreach(var item in group)
            {
                // find you whether is the first item of the group and set the css class
                var itemClass = item.IsFirst("first item left", "item left");
                
                // If there is not photo, fallback to the placeholder
                var src = @item.Cropper ?? "/images/Placeholders/photo_placeholder.gif";
                <div class="image">
                 @if (Model.HasValue("Cropper"))
    {
        <img src="@Model.Cropper.Find("@name", "250").url" /><br />
        
    }
                </div>            
            }
            
            // Clear after each group of 3
            <div class="clearBoth">&nbsp;</div>
        }
        </div>

     

  • Charles Afford 1163 posts 1709 karma points
    Aug 24, 2013 @ 20:20
    Charles Afford
    0

    Hi, why do is so diffrent about doing it in MVC?  What are you having problems with?

  • Keith R Hubbard 175 posts 403 karma points
    Aug 24, 2013 @ 20:57
    Keith R Hubbard
    0

    nodeById does not work with MVC Model.  I have a content structure attached below and I want to pull content from a specific ID in a folder because it would give the direct links.  The Home Links folder just has the content I want to link to.  The home links folder has an alias of homeLinks and the children have an alias of homelink. I then should be able to pull a CropUp image and link to the correct page from my home page.  

     

      

  • Charles Afford 1163 posts 1709 karma points
    Aug 24, 2013 @ 21:10
    Charles Afford
    0

    Could you explain what you are having problems with using MVC?  This does not really make sense :)  Charlie

  • Charles Afford 1163 posts 1709 karma points
    Aug 24, 2013 @ 21:13
    Charles Afford
    0

    Why have you got two nodes called twon nodes called Golf Cars?  Could you briefly explain the problem you are trying to solve and tell us what doc types and templates you have setup and i will help :).  Charlie.

    What you are doing at the moment, feels really wrong.

  • Keith R Hubbard 175 posts 403 karma points
    Aug 24, 2013 @ 21:46
    Keith R Hubbard
    0

    ok i made some changes. and this is what i have so far.  this code is a partial called homelinks.cshtml.

     

    here is the home page. 

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Butterfields_master.cshtml";
        var homepage = Model.Content.AncestorOrSelf(1);
        var homeLinks = Umbraco.TypedContent(1388);
    }


        @Umbraco.RenderMacro("Slidesonhome")

     


        @Html.Partial("~/Views/Partials/HomeLinks.cshtml")
       
               

    @Umbraco.Field("summary")


           

    here is the partial

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @using Eksponent.CropUp
    @{
        Layout = null;
       
    }
    @{
        // Get all child items based on the document type 'Golf Cars' and group them is 4
       


        @foreach (var group in Umbraco.TypedContent(1388).Children.InGroupsOf(3))
        {
           foreach(var item in group)
            {
                // find you whether is the first item of the group and set the css class
                var itemClass = item.IsFirst("first item left", "item left");

                string imageThumbUrl;
              
               if (item.HasValue("umbracoFile"))
                    {
                     var imageUrl = "~" + item.GetPropertyValue("umbracoFile");
                     imageThumbUrl = CropUp.GetUrl(imageUrl, new ImageSizeArguments() { CropAlias = "thumbnail" });
                    }
                    else
                    {
                        // If there is no photo, fallback to the placeholder               
                        imageThumbUrl = "/img/pathtothumbplaceholder.jpg";
                    }
               

                        @item.Name
                       
                   

                }          

                // Clear after each group of 4
               
            }
       


    }

    I now need to get my route to specific nodes. 

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 24, 2013 @ 21:52
    Jeavon Leopold
    0

    Try @Html.Partial("HomeLinks",Model.Content) to pass the model to your partial view

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 24, 2013 @ 21:55
    Jeavon Leopold
    0

    Actually, just change the inherits of your partial to @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

  • Keith R Hubbard 175 posts 403 karma points
    Aug 24, 2013 @ 22:26
    Keith R Hubbard
    0

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    @using Eksponent.CropUp
    @{
        Layout = null;
    }
    @{
        // Get all child items based on the document type 'CWS_NewsItem' and group them is 4
        <div class="FeaturedProduct">
        @foreach (var group in Umbraco.TypedContent(1388).Children.InGroupsOf(3))
        {
           foreach(var item in group)
            {
                // find you whether is the first item of the group and set the css class
                var itemClass = item.IsFirst("first item left", "item left");

                string imageThumbUrl;
              
               if (item.HasValue("umbracoFile"))
                    {
                     var imageUrl = "~" + item.GetPropertyValue<string>("umbracoFile");
                     imageThumbUrl = CropUp.GetUrl(imageUrl, new ImageSizeArguments() { CropAlias = "thumbnail" });
                    }
                    else
                    {
                        // If there is no photo, fallback to the placeholder               
                        imageThumbUrl = "/img/pathtothumbplaceholder.jpg";
                    }
                                           
                <div class="@itemClass">
                        @if (Umbraco.TypedContent(1388).HasValue("contentPicker"))
                        {
                            var node = Umbraco.TypedContent(Umbraco.TypedContent(1388).GetPropertyValue<int>("contentPicker"));
                           
                        <a href="@node.Url"><img src="@imageThumbUrl" alt="@item.Name"/></a>
                        }
                    </div>
                }          

                // Clear after each group of 4
                <div class="clearBoth"> </div>
            }
        </div>
    }

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 24, 2013 @ 22:47
    Jeavon Leopold
    0

    What property editor are you using for urlContentPicker, standard content picker or ucomponents or...?

  • Keith R Hubbard 175 posts 403 karma points
    Aug 24, 2013 @ 22:54
    Keith R Hubbard
    0

    Standard content picker.  I tried Ucomponents with no luck either. just updated above but it does not like URL like the documentation says. 

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 24, 2013 @ 22:56
    Jeavon Leopold
    0

    For standard content picker, try:

      if (Model.HasValue("urlContentPicker")){
        <a href="@Umbraco.TypedContent(Model.GetPropertyValue<int>("urlContentPicker")).Url"><img src="@imageThumbUrl" alt="@item.Name"/></a>
      }
    
  • Keith R Hubbard 175 posts 403 karma points
    Aug 24, 2013 @ 23:02
    Keith R Hubbard
    0

    CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Url' and no extension method 'Url' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

     

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    @using Eksponent.CropUp
    @{
        Layout = null;
    }
    @{
        // Get all child items based on the document type 'CWS_NewsItem' and group them is 3
        <div class="FeaturedProduct">
        @foreach (var group in Umbraco.TypedContent(1388).Children.InGroupsOf(3))
        {
           foreach(var item in group)
            {
                // find you whether is the first item of the group and set the css class
                var itemClass = item.IsFirst("first item left", "item left");

                string imageThumbUrl;
              
               if (item.HasValue("umbracoFile"))
                    {
                     var imageUrl = "~" + item.GetPropertyValue<string>("umbracoFile");
                     imageThumbUrl = CropUp.GetUrl(imageUrl, new ImageSizeArguments() { CropAlias = "thumbnail" });
                    }
                    else
                    {
                        // If there is no photo, fallback to the placeholder               
                        imageThumbUrl = "/img/pathtothumbplaceholder.jpg";
                    }
                                           
                <div class="@itemClass">
                        @if (Model.HasValue("contentPicker"))
                        {
                         <a href="@Umbraco.TypedContent(Model.GetPropertyValue<int>("urlContentPicker")).Url"><img src="@imageThumbUrl" alt="@item.Name"/></a>
                        }
                    </div>
                }          

                // Clear after each group of 3
                <div class="clearBoth"> </div>
            }
        </div>
    }

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 24, 2013 @ 23:07
    Jeavon Leopold
    1

    Ok,

     if (Model.HasValue("urlContentPicker")){
        var node = Umbraco.TypedContent(Model.GetPropertyValue<int>("urlContentPicker"));
        <a href="@node.Url"><img src="@imageThumbUrl" alt="@item.Name"/></a>
      }
    
  • Keith R Hubbard 175 posts 403 karma points
    Aug 24, 2013 @ 23:13
    Keith R Hubbard
    0

    my intellesense has no url it has UrlName.  Got me swinging

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 24, 2013 @ 23:16
    Jeavon Leopold
    0

    Bonkers, does it YSOD with .Url?

  • Keith R Hubbard 175 posts 403 karma points
    Aug 24, 2013 @ 23:19
    Keith R Hubbard
    0

    sorry forgot colin

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 24, 2013 @ 23:30
    Jeavon Leopold
    1

    Hmm, maybe a sort if bug.

    Can you try adding at the top of the partial after the inherits

    @using Umbraco.Core
    @using Umbraco.Web
    @using Umbraco.Core.Models
    
  • Keith R Hubbard 175 posts 403 karma points
    Aug 24, 2013 @ 23:34
    Keith R Hubbard
    0

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    @using Umbraco.Core
    @using Umbraco.Web
    @using Umbraco.Core.Models
    @using Eksponent.CropUp
    @{
        Layout = null;
    }
    @{
        // Get all child items based on the document type 'CWS_NewsItem' and group them is 4
        <div class="FeaturedProduct">
        @foreach (var group in Umbraco.TypedContent(1388).Children.InGroupsOf(3))
        {
           foreach(var item in group)
            {
                // find you whether is the first item of the group and set the css class
                var itemClass = item.IsFirst("first item left", "item left");

                string imageThumbUrl;
              
               if (item.HasValue("umbracoFile"))
                    {
                     var imageUrl = "~" + item.GetPropertyValue<string>("umbracoFile");
                     imageThumbUrl = CropUp.GetUrl(imageUrl, new ImageSizeArguments() { CropAlias = "thumbnail" });
                    }
                    else
                    {
                        // If there is no photo, fallback to the placeholder               
                        imageThumbUrl = "/img/pathtothumbplaceholder.jpg";
                    }
                                           
                <div class="@itemClass">
                        @if (Model.HasValue("contentPicker"))
                        {
                            var node = Umbraco.TypedContent(Model.GetPropertyValue<int>("contentPicker"));
                         <a href="@node.Url"><img src="@imageThumbUrl" alt="@item.Name"/></a>
                        }
                    </div>
                }          

                // Clear after each group of 4
                <div class="clearBoth"> </div>
            }
        </div>
    }

     

    this is still getting the same error

  • Charles Afford 1163 posts 1709 karma points
    Aug 24, 2013 @ 23:52
    Charles Afford
    0

    Keith  :)  Why have you got two nodes of the same in your content tree? And are you trying to create a custom root or just get to the node?.  Charlie.  Why are you using TypedContent? What does UrlName return?

  • Keith R Hubbard 175 posts 403 karma points
    Aug 25, 2013 @ 00:05
    Keith R Hubbard
    0

    @Charles I changed the nodes to have link on the end.  I want to have specific links to pages and not all nodes.  The company has Golf Cars and Turk mant equipment and I just want vistitors to click on those node links to get to where they need to go.  

     

    the problem I have now is the partial does not find Url for the contentpicker. 

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 25, 2013 @ 00:11
    Jeavon Leopold
    0

    I just tested this on v6 and you shouldn't be having this problem.

    I'm wondering if you have an issue with the web.config inside your Views folder, can you post the contents and also ensure it is included in your solution?

  • Charles Afford 1163 posts 1709 karma points
    Aug 25, 2013 @ 00:14
    Charles Afford
    0

    How are the members selecting this pages (users of the site) and how are the links created?  I am stuggleing to see any needs to those link nodes you have?

    When you say stuggleing to find the url for the content picker.  On which node is the property? can you access the property?

  • Keith R Hubbard 175 posts 403 karma points
    Aug 25, 2013 @ 00:16
    Keith R Hubbard
    0

    Here is the views Web.Config

     

    <?xml version="1.0"?>

    <configuration>
      <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
          <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
      </configSections>

      <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
          <namespaces>
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
                    <add namespace="Umbraco.Web" />
                    <add namespace="Umbraco.Core" />
                    <add namespace="Umbraco.Core.Models" />
                    <add namespace="Umbraco.Web.Mvc" />               
                </namespaces>
        </pages>
      </system.web.webPages.razor>

      <appSettings>
        <add key="webpages:Enabled" value="false" />
      </appSettings>

      <system.web>
        <httpHandlers>
          <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
        </httpHandlers>

        <!--
            Enabling request validation in view pages would cause validation to occur
            after the input has already been processed by the controller. By default
            MVC performs request validation before a controller processes the input.
            To change this behavior apply the ValidateInputAttribute to a
            controller or action.
        -->
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <controls>
            <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
          </controls>
        </pages>
      </system.web>

      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />

        <handlers>
          <remove name="BlockViewHandler"/>
          <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
        </handlers>
      </system.webServer>
    </configuration>

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 25, 2013 @ 00:16
    Jeavon Leopold
    0

    Ok, sorry but you have hit a known bug that was only fixed in v6. You will have to upgrade to use this approach.....

    http://issues.umbraco.org/issue/U4-1065

  • Charles Afford 1163 posts 1709 karma points
    Aug 25, 2013 @ 00:23
    Charles Afford
    0

    Jeavon, what versions does this effect?  Charlie.

  • Keith R Hubbard 175 posts 403 karma points
    Aug 25, 2013 @ 00:43
    Keith R Hubbard
    0

    Charles read the issue.  http://issues.umbraco.org/issue/U4-1065

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 25, 2013 @ 00:47
    Jeavon Leopold
    0

    Charlie, looks like all v4 versions, slightly odd that it was fixed in v6.0 but not back ported to v4 branch. As a general rule I only use Mvc in v6, I think the v4 Mvc support was beta (ish)

  • Charles Afford 1163 posts 1709 karma points
    Aug 25, 2013 @ 01:05
    Charles Afford
    0

    Thanks :).  Was just wondering.  I have been using it with 4.10 + and have only had a few problems with context and AJAX post backs but nothing major.  Always have not been using any dynamic stuff though.  Charlie :)

  • Keith R Hubbard 175 posts 403 karma points
    Aug 25, 2013 @ 01:07
    Keith R Hubbard
    0

    Charles thanks for you input!!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 25, 2013 @ 08:27
    Jeavon Leopold
    0

    I've been reading a bit deeper into the issue and it seems you might be able to do this (without upgrading)

    if (Model.HasValue("urlContentPicker")){
        var node = Umbraco.TypedContent(Model.GetPropertyValue<int>("urlContentPicker"));
        <a href="@node.NiceUrl()"><img src="@imageThumbUrl" alt="@item.Name"/></a>
      }
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 25, 2013 @ 08:29
    Jeavon Leopold
    0

    @Charles, how have you been getting the Url of the dynamic CurrentPage in your v4 Mvc views?

    @CurrentPage.Url or @CurrentPage.NiceUrl() or something else?

  • Charles Afford 1163 posts 1709 karma points
    Aug 25, 2013 @ 14:43
    Charles Afford
    0

    It was a while ago but it would have been one of those two.  @CurrentPage.Url or @CurrentPage.NiceUrl()

    It might be worth trying to do this 'strongly typed' rather than using var?  I am not sure what the complier is resolving the type as, dont know if this could be a problem?

    Charlie.

Please Sign in or register to post replies

Write your reply to:

Draft