Copied to clipboard

Flag this post as spam?

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


  • Sébastien Richer 194 posts 430 karma points
    Jun 12, 2013 @ 23:09
    Sébastien Richer
    0

    Getting IPublishedContent in SurfaceController?

    I have this SurfaceController to ajax in my "projects" in my page. In there I do:

                var lang = umbraco.uQuery.GetNodeByUrl("/");
                var projects = lang.GetDescendantNodesByType("Projet");
                var filteredProjects = new List<Node>();
                var filterBy = umbraco.uQuery.GetNode(id);

    Stuff like that. I keep getting "Node" types instead of what I normally get in my Views. How should I be doing this?

    (I tried using Umbraco.TypedContent but that does'nt work in surface controllers.)

    Thanks for any help!

     

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Jun 13, 2013 @ 09:30
    Andy Butland
    0

    Umbraco.TypedContent should be available in surface controllers.  Just looking at an example I have - make sure your controller class inherits from SurfaceController and you have a using statment for Umbraco.Web.Mvc.

  • Sébastien Richer 194 posts 430 karma points
    Jun 13, 2013 @ 15:26
    Sébastien Richer
    0

    Hi Andy,

    Here's what I tried:

                var lang = umbraco.uQuery.GetNodeByUrl("/");
                var node = Umbraco.TypedContent(lang.Id);
                node.

    When I type that . VS Intellisense does'nt give me the "Descendants()" I expect from IPublishedContent. The object type returned is Umbraco.Core.Models.IPublishedContent.

    I do have the using Umbraco.Web.Mvc; at the top, but VS marks it grey like it's unused.

    My class is : public class ProjectsController : Umbraco.Web.Mvc.SurfaceController

    Now I think in Umbraco pre v6 surface controllers needed the suffix and should thusly be named ProjectsSurfaceController, but is that still valid? This doesn't change my missing "Descendants()" call though...

    Anything else I should look for?

     

    Actually here is the full .cs (there is some weird code in there, don't judge haha):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;
    using System.Web.Mvc;
    using MyApp.Models;
    using Umbraco.Core.Models;
    using Umbraco.Web.Models;
    using Umbraco.Web.Mvc;
    using umbraco;
    using umbraco.NodeFactory;
    
    namespace MyApp.SurfaceControllers
    {
        public class ProjectsController : Umbraco.Web.Mvc.SurfaceController
        {
            [System.Web.Mvc.HttpPost]
            public ActionResult Index(string expertiseId, string subexpertiseId)
            {
                return Content("ok");
            }
    
            // [System.Web.Mvc.HttpPost]
            public ActionResult Filter(string id)
            {
                var lang = umbraco.uQuery.GetNodeByUrl("/");
                var projects = lang.GetDescendantNodesByType("Projet");
                var filteredProjects = new List();
                var filterBy = umbraco.uQuery.GetNode(id);
    
                // var node = Umbraco.TypedContent(lang.Id);
    
                /*if (filterBy.NodeTypeAlias == "Expertise")
                {
                    filteredProjects =
                        projects.Where(
                            x =>
                            filterBy.ChildrenAsList.Any(
                                y => x.GetProperty("expertises").ToString().Contains("" + y.Id + ""))).ToList();
                }
                else if (filterBy.NodeTypeAlias == "Marche")
                {
                    filteredProjects =
                        projects.Where(
                            x => x.GetProperty("marches").ToString().Contains("" + id + "")).ToList();
                }
                else if (filterBy.NodeTypeAlias == "SousExpertise")
                {
                    filteredProjects =
                        projects.Where(
                            x => x.GetProperty("expertises").ToString().Contains("" + id + "")).ToList();
                }*/
    
                /*var result = "";
                foreach (var node in filteredProjects)
                {
                    result += " " + node.GetProperty("titre").ToString();
                }*/
    
                return Content("ok");
            }
        }
    }

     

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Jun 13, 2013 @ 17:30
    Andy Butland
    104

    I think if you add as well...

    using Umbraco.Web;

    ...that should do it to get access to .Descendents.

    The reason it needs that is that Descendents is an extension method held within this namespace.  So if you haven't imported that it won't appear in intellisense or be available for use.

    Andy

  • Sébastien Richer 194 posts 430 karma points
    Jun 13, 2013 @ 17:54
    Sébastien Richer
    0

    Yes! This is it! Thanks for the help Andy!

  • ibrahim TUNC 54 posts 132 karma points
    Sep 15, 2014 @ 08:41
    ibrahim TUNC
    0

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

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

    Source Error:

     
    Line 396:        
    Line 397:                        <li class="@isPageSelected">
    Line 398: <a href="@page.Url">@page.PageName</a> Line 399:
    Line 400:                            @if (CurrentPage.Children.Where("umbracoNaviHide!= true").Count() > 1 && page.IsAncestorOrSelf(Model.Content))


    Source File: c:\Users\ibrahim.tunc\Documents\My Web Sites\UIS\Views\ContentPage.cshtml    Line: 398 

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Sep 15, 2014 @ 10:15
    Andy Butland
    0

    Try page.Name or page.GetPropertyValue<string>("pageName") - the latter if "pageName" is a custom field on your document type.

    Andy

  • ibrahim TUNC 54 posts 132 karma points
    Sep 15, 2014 @ 11:34
    ibrahim TUNC
    0
    input
                    <ul>
                        @foreach (var page in Model.Content.Siblings())
                        {
                        <li>
                            <a href="@page.Url">page.GetPropertyValue<string>("pageName")a> li> } ul>
    output 

     

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Sep 15, 2014 @ 16:48
    Andy Butland
    0

    You need an @ symbol before page.GetPropertyValue

  • ibrahim TUNC 54 posts 132 karma points
    Sep 16, 2014 @ 10:32
    ibrahim TUNC
    0

    hi! Andy. Thanks for helps. 

    The problem was solved. 

    I've added the following code to the top of the code block. 

                  @{
                        @*Get the root of the website *@
                        var root = CurrentPage.AncestorOrSelf(2);
                    }  

     

    All relevant sections

                <!-- Left Side (Sub Navigation)-->
                <div class="four columns">
    
                    @{
                        @*Get the root of the website *@
                        var root = CurrentPage.AncestorOrSelf(2);
                    }                  
    
                    <div class="sideNavTitle" style="margin-left: 10px;">@Umbraco.RenderMacro("CurrentPage")</div>
                    <div class="sideNav" style="margin-left: 10px;">
    
                    <ul>
                        @foreach (var page in root.Children.Where("Visible"))
                        {
                        <li>
                            <a href="@page.Url">@page.pageName</a>
                        </li>
                        }   
                    </ul>
    
        <br />
                    <br />
    
                    </div>
                </div>
                <!-- End Left Side -->
    
Please Sign in or register to post replies

Write your reply to:

Draft