Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm currently experimenting with umbraco and found the Umbraco.NiceUrl(int) helper and wanted to write my own NiceUrl(string) helper.
So i created the below extension
public static class UmbracoExtensions
public static string NiceUrl(this UmbracoHelper helper, string cTypeAlias)
var node = helper.TypedContentAtRoot().DescendantsOrSelf<IPublishedContent>()
.Where(x => x.Name == cTypeAlias).FirstOrDefault();
if (node != null)
And it works fine if i put a @using at the top of the view.
My question is how do i get this to automatically be a part of the UmbracoHelper class without using a @using at the top of every view?
Would it be at application start?
You have a couple of options to this really.
The first (Not recommended but is an option):
Change the namespace of your extension method to be the same as the UmbracoHelper.
The second (a much better idea):
Edit the Web.Config file found in the Views folder. In there you will see a section that looks like this:
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Umbraco.Web" />
<add namespace="Umbraco.Core" />
<add namespace="Umbraco.Core.Models" />
<add namespace="Umbraco.Web.Mvc" />
<add namespace="umbraco" />
<add namespace="Examine" />
All you need to do is add your namespace into that list and it will be included in all of your views instead of you typing it out all the time.
You can place the namespace it in the /views/web.config that way you won't need to place it in each view...
Thank you both,
i can't believe i didn't think of that myself. I was trying to be too clever with it all lol.
VS2019 doesn't like it. It does compile but shows a bunch of errors.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted