I am trying to set up a (basically empty) custom class in the App_Code folder, to use as a starting point for some code I'd like to be able to reuse in my templates.
Right now I have the following in my App_Code file:
using umbraco.cms.businesslogic;
using Umbraco.Core.Models;
using System.Linq;
using System.Globalization;
namespace MyNamespace
{
public class TranslationHelper
{
public IPublishedContent GetTranslatedContentNode(IPublishedContent Model, string currentCulture)
{
IPublishedContent contentNode = Model;
return contentNode;
}
}
}
...and the following in my template:
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.TextPage>
@inherits MyNamespace.TranslationHelper
@using ContentModels = Umbraco.Web.PublishedContentModels;
@{
Layout = "Homepage.cshtml";
}
@{
var contentNode = new MyNamespace.TranslationHelper.GetTranslatedContentNode(Model);
}
But I am getting the following error:
CS0115: 'ASP._Page_Views_TextPage_cshtml.Execute()': no suitable method found to override
Can anyone see what I'm doing wrong? Any help would be greatly appreciated.
using umbraco.cms.businesslogic;
using Umbraco.Core.Models;
namespace MyNamespace
{
public class TranslationHelper
{
public IPublishedContent Title { get; set; }
public static IPublishedContent GetTranslatedContentNode(IPublishedContent model)
{
IPublishedContent contentNode = model;
return contentNode;
}
}
}
Help implementing a custom C# class in App_Code?
Hi,
I am trying to set up a (basically empty) custom class in the App_Code folder, to use as a starting point for some code I'd like to be able to reuse in my templates.
Right now I have the following in my App_Code file:
...and the following in my template:
But I am getting the following error:
Can anyone see what I'm doing wrong? Any help would be greatly appreciated.
Thanks,
David
Hi David
2 questions:
Cheers
Nigel
Looks like I figured it out myself with a little more searching on Our.
This was the thread that helped me out: https://our.umbraco.org/forum/developers/razor/44015-Access-App_Code-classes-in-Razor
And here's the code I ended up with:
.CS file in App_Code:
Template:
is working on a reply...