更新时间:2023-02-14 16:24:06
你有没有加入辅助的命名空间到你的浏览/ web.config中?
Have you added the helper's namespace to your Views/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="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="CUSTOM_NAMESPACE" />
</namespaces>
</pages>
</system.web.webPages.razor>
如果您使用的是RC,如果你在一个早期测试版,你需要添加命名空间中的页面或Global.asax中以上才有效。
The above will only work if you're using an RC, if you're on an early Beta, you'll need to add the namespace in the page or Global.asax.
另外,我建议改变返回类型为 HtmlString
。
Also, I'd suggest changing the return type to HtmlString
.
return new HtmlString(STRING_VALUE);