Ror*_*san 6 c# razor asp.net-mvc-3
我试图在局部视图中使用字符串扩展方法.我收到以下错误:
'string'不包含'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());
}
}
}
Run Code Online (Sandbox Code Playgroud)
根据前一个问题,我需要将命名空间添加到web.config,但是我已经完成了这个并且仍然收到相同的错误消息.但奇怪的是,我确实得到了扩展方法的intellisense?
<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>
Run Code Online (Sandbox Code Playgroud)
谁能解释为什么会这样?
谢谢
如果命名空间声明位于根视图目录 web.config 的 system.web.webPages.razor/namespaces 元素中,则此操作应该有效。如果失败,请尝试在视图顶部使用显式 @using 语句,而不使用任何 web.config 语句。它“应该”有效。
PS 是 ReSharper 智能感知还是 VS?ReSharper 明确告诉我,如果 web.config 条目不在范围内,则需要 @using。
| 归档时间: |
|
| 查看次数: |
1903 次 |
| 最近记录: |