好吧,我的问题曾与做叫它命名空间...所以我有在\ Views \ Shared \ HtmlHelpers.cs:
public static class Html
{
public static MvcHtmlString Image(this HtmlHelper helper, string src, object htmlAttrs = null)
{
我通常从我的网页访问像这样:
@Html.Image("/path/to/image")
在App_Code文件\ Helpers.cshtml
:
@helper AddButton(string path)
{
var Html = ((System.Web.Mvc.WebViewPage) WebPageContext.Current.Page).Html;
@Html.Image(path);
}
但智能感知强调有 “图像”,并抱怨:
'System.Web.Mvc.HtmlHelper<object>' does not contain a definition for 'Image'
and no extension method 'Image' accepting a first argument of type
'System.Web.Mvc.HtmlHelper<object>' could be found (are
you missing a directive or an assembly reference?)
的原因似乎是帮助者.cshtml需要有名称空间的@using
...在我的常规页面上,名称空间包含在我的web.config中,但此页面似乎不受此机制的限制
这将有助于看到你尝试过哪两种方式。你是否像这样使用了完整的助手路径:@ CustomHelpers.Truncate(ViewBag.Message,8)在这种情况下,你不需要使用CustomHelpers.cshtml文件的“使用”? – 2011-06-12 04:21:08