Cannot use extension method in partial view

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" /> <!-- Other namespaces... --> <add namespace="PCCMS.Core.Libraries" /> </namespaces> </pages> </system.web.webPages.razor> 

Can someone explain why this is?

thanks

+6
source share
2 answers

This should work if the namespace declaration is in the system.web.webPages.razor / namespaces element of your web.config view root directory. If this fails, try using the explicit @using operator at the top of the view without any web.config instructions. He must "work."

PS Is it ReSharper intellisense or VS? ReSharper explicitly tells me that @using is required if the web.config entry is not in scope.

+1
source

Does an error occur when starting in the VS debugger or in a test or production system? Make sure that your module containing the extension is installed correctly (and updated correctly). Also, try running "iisreset" from the command line.

0
source

Source: https://habr.com/ru/post/920688/


All Articles