Copied to clipboard

Flag this post as spam?

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


  • Desley 44 posts 169 karma points
    May 27, 2014 @ 11:12
    Desley
    0

    GetProperty at backend

    Hi,

    I am trying to get the property value from the homepage into the backend umbraco file: Default.cshtml.

    I have done it as such on the frontend:

    var homePage = CurrentPage.AncestorsOrSelf(1).First();
    var layoutColor = homePage.GetPropertyValue("layoutColor");
    

    But this doesn't seem to work in the backend files.

    Hope someone knows how this can be done!

  • Amir 75 posts 224 karma points
    May 27, 2014 @ 11:23
    Amir
    0

    Hi,

    What if you use this?

    Node HomeNode = umbraco.NodeFactory.Node.GetCurrent().GetAncestorOrSelfNodes().First(n => n.NodeTypeAlias == "HomePageNodeAlias");
    var layoutColor  = HomeNode.GetProperty("layoutColor");

     

     

     

  • Desley 44 posts 169 karma points
    May 27, 2014 @ 11:55
    Desley
    0

    It gives me the message: There is no current node.

  • Amir 75 posts 224 karma points
    May 27, 2014 @ 12:00
    Amir
    0

    Strange, As long as it is bounded to a node, there must be a currentNode!

    is this working?

     

    umbraco.presentation.nodeFactory.Node node = umbraco.presentation.nodeFactory.Node.GetCurrent() 

     

    Is Default.cshtml a view or macroscript?

     

  • Desley 44 posts 169 karma points
    May 27, 2014 @ 12:10
    Desley
    0

    It gives me the message: Object reference not set to an instance of an object.

    It is a view generated by Umbraco.

  • Amir 75 posts 224 karma points
    May 27, 2014 @ 12:33
    Amir
    0

    Did you add the required refences?

    Can you share the stack trace for your error message?

    Also are you able to run your code in debug mode and check the variables there?

     

  • Desley 44 posts 169 karma points
    May 27, 2014 @ 12:43
    Desley
    0

    The last try doesn't need any references?

    I can run it in debug mode but can't check the variables as it gives me the error before setting the variable.

    The stacktrace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       umbraco.presentation.nodeFactory.Node.GetCurrent() +248
       ASP._Page_umbraco_Views_Default_cshtml.Execute() in c:\Users\desley\Documents\Visual Studio 2013\Projects\Zorgnaarwens\Current\Src\ZorgNaarWens.Umbraco.Web\umbraco\Views\Default.cshtml:12
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +119
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +743
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +380
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +151
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
       System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +74
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +388
       System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +72
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +388
       System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +72
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +303
       System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +155
       System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +184
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +136
       System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +40
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
       System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
       System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
       System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
       System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
       System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +45
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
       System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
       System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9690172
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
    
  • Amir 75 posts 224 karma points
    May 27, 2014 @ 14:54
    Amir
    0

    No in last try there is no additional references is required.

    Can you make sure you have following DLLs in your solution's references?

    cms.dll, businesslogic.dll, umbraco.dll and interfaces.dll

  • Desley 44 posts 169 karma points
    May 27, 2014 @ 14:59
    Desley
    0

    Yes, all are included. The file should be in every Umbraco 7 install if I'm not mistaken. Perhaps you could try it yourself and see if it works. Pretty sure it's not my solution that is the problem though, but the method trying to collect the property.

  • Amir 75 posts 224 karma points
    May 27, 2014 @ 15:02
    Amir
    0

    Also can you try

    Node x = new Node(-1);

    and see whether it returns the root node of you umbraco?

  • Amir 75 posts 224 karma points
    May 27, 2014 @ 15:04
    Amir
    0

    Yes that should be there in any installations. I did try it and it works fine on mine, thats why I am asking you some obvious questions too see if anything is in its place?

     

  • Desley 44 posts 169 karma points
    May 27, 2014 @ 15:14
    Desley
    0

    It does return the root node.

  • Amir 75 posts 224 karma points
    May 27, 2014 @ 16:31
    Amir
    0

    Have you tried Cleaning your solution and Republish entire site from Umbraco?

  • Desley 44 posts 169 karma points
    May 27, 2014 @ 16:43
    Desley
    0

    Same results.

  • Vasia Vasia 49 posts 241 karma points
    May 27, 2014 @ 17:10
    Vasia Vasia
    0

    Please try so:

    int nodeId = Node.getCurrentNodeId();                                                                                                 var helper = new UmbracoHelper(UmbracoContext.Current);
    content = helper.TypedContent(nodeId).AncestorsOrSelf(1).FirstOrDefault();
    if (content != null)
    {
         content.GetPropertyValue("layoutColor");
    }

     

    Best, Oleg

  • Desley 44 posts 169 karma points
    May 28, 2014 @ 09:13
    Desley
    0

    Gives me the message: There is no current node.

    Does it work for you when you place it in Default.cshtml? Wonder what is wrong with my solution, if so.

  • Vasia Vasia 49 posts 241 karma points
    May 28, 2014 @ 09:33
    Vasia Vasia
    0

    Yes, it works for me.

    I think something wrong with your solution. Please try to re-install it and then try again.

Please Sign in or register to post replies

Write your reply to:

Draft