If you want to create a Razor helper to be reused by your views, I would recommend you to get the node in your views (or controllers in a view model) and pass it to you helper function, instead getting the node in the helper itself.
@using Umbraco
@using Umbraco.Core.Services
@using Umbraco.Web
@using Umbraco.Web.Composing
@using Umbraco.Core.Models.PublishedContent
@using System.Web
@functions{
public static IPublishedContent test(int Id){
var ttt = Umbraco.Content(Id);
return null; /* just testing to see if it compiles */
}...
Returns error:
Compiler Error Message: CS0234: The type or namespace name 'Content' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
Source Error:
Line 16:
Line 17: public static IPublishedContent test(int Id){
Line 18: var ttt = Umbraco.Content(Id);
Line 19: return null;
Line 20: }
Do I need to include a different 'using' namespace? (ythis is cshtml in the app_code folder)
How to get node by id in app_code cshtml
Not sure how to get a node by id and return its property values in a generic razor file in app_code.
Any suggestions gratefully received.
If you want to create a Razor helper to be reused by your views, I would recommend you to get the node in your views (or controllers in a view model) and pass it to you helper function, instead getting the node in the helper itself.
Hey
use
var content = Umbraco.Content(1063)
Or use content services.
Returns error:
Do I need to include a different 'using' namespace? (ythis is cshtml in the app_code folder)
Thanks
is working on a reply...