I am trying to use a line extension method in a partial view. I get the following error:
'string' does not contain a definition for 'TruncateAtCharacter'
Here is an 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 a namespace in web.config, however I did this and I still get the same error message. However, what is strange that I 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" /> <add namespace="PCCMS.Core.Libraries" /> </namespaces> </pages> </system.web.webPages.razor>
Can someone explain why this is?
thanks
source share