我正在尝试在部分视图中使用字符串扩展方法。我收到以下错误:
“字符串”不包含“TruncateAtCharacter”的定义
这是扩展方法:
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());
}
}
}
根据这个先前的问题,我需要将命名空间添加到 web.config,但是我已经这样做了,我仍然收到相同的错误消息。奇怪的是,我确实得到了扩展方法的智能感知?
<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>
谁能解释这是为什么?
谢谢