I am trying to use a string extension method in a partial view. I get the following error:
'string' does not contain a definition for 'TruncateAtCharacter'
Here is the extension method:
namespace PCCMS.Core.Libraries {
public static class Extensions {
public static string TruncateAtCharacter(this string input, int length) {
if (String.IsNullOrEmpty(input) || input.Length < length)
return input;
return string.Format("{0}...", input.Substring(0, length).Trim());
}
}
}
According to this previous question I need to add the namespace to web.config, however I have done this and I still receive the same error message. What's odd though, is that I do get intellisense for the extension method?
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="PCCMS.Core.Libraries.ClientWebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<!-- Other namespaces... -->
<add namespace="PCCMS.Core.Libraries" />
</namespaces>
</pages>
</system.web.webPages.razor>
Can anyone explain why this is?
Thanks