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.)
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.
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");
}
}
}
...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.
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
I've added the following code to the top of the code block.
@{@*Get the root of the website *@varroot=CurrentPage.AncestorOrSelf(2);}
All relevant sections
<!-- Left Side (Sub Navigation)--><divclass="four columns">@{@*Get the root of the website *@varroot=CurrentPage.AncestorOrSelf(2);}<divclass="sideNavTitle"style="margin-left: 10px;">@Umbraco.RenderMacro("CurrentPage")</div><divclass="sideNav"style="margin-left: 10px;"><ul>@foreach(varpageinroot.Children.Where("Visible")){<li><ahref="@page.Url">@page.pageName</a></li>}</ul><br/><br/></div></div><!-- End Left Side -->
Getting IPublishedContent in SurfaceController?
I have this SurfaceController to ajax in my "projects" in my page. In there I do:
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!
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.
Hi Andy,
Here's what I tried:
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):
I think if you add as well...
...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
Yes! This is it! Thanks for the help Andy!
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
Try page.Name or page.GetPropertyValue<string>("pageName") - the latter if "pageName" is a custom field on your document type.
Andy
output
Where am I doing wrong? Can you help me please.
You need an @ symbol before page.GetPropertyValue
hi! Andy. Thanks for helps.
The problem was solved.
I've added the following code to the top of the code block.
All relevant sections
is working on a reply...