1
votes

I am trying to get a node by it's ID through a Razor script, but I keep getting this error:

error CS0118: 'umbraco.MacroEngines.BaseContext.Node' is a 'property' but is used like a 'type'

Here is my code:

@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var node = new Node(Parameter.newsnode);
}

I feel like I'm missing something very basic here, just can't seem to figure it out.

Umbraco 4.11.1

4

4 Answers

4
votes

Here's how I generally do this:

@inherits umbraco.MacroEngines.DynamicNodeContext
@{
  // Get some default node id if this is null or empty
  var newsNodeId = String.IsNullOrEmpty(Parameter.newsnode) ? "1022" : Parameter.newsnode;

  // Get the node using this helper method on DynamicNode
  var newsNode = @Model.NodeById(newsNodeId);
}
3
votes

It was as simple as including Umbraco.NodeFactory

@using umbraco.NodeFactory
1
votes

There is this simple function :

@{
    var node = @Library.NodeById(Model.Id);
}

@* OR *@

@{
    var node = @Library.NodeById(1250);
}
1
votes

If you are programming something for Umbraco and fast want to know the availble options for your Razor code you could use the cheatSheet: http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet. Also read this documentation: http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets