好的,我正在尝试实现复读器扩展方法到HtmlHelper,正如Phil Haack的博客http://haacked.com/archive/2008/05/03/code-based-repeater-for-asp.net-mvc.aspx中所解释的。然而,当我尝试在我的视图中使用它时,我得到了一个编译错误'System.Web.Mvc.HtmlHelper‘不包含' Repeater’的定义。
下面是我的扩展类:
namespace MyAwesomeBlog.Helpers {
public static class HtmlHelpers {
public static void Repeater<T>(this HtmlHelper html
, IEnumerable<T> items
, Action<T> render
, Action<T> renderAlt) {//实现不相关});}
public static void Repeater<T>(this HtmlHelper html
, Action<T> render
, Action<T> renderAlt) {//实现不相关});}
public static void Repeater<T>(this HtmlHelper html
, string viewDataKey
, Action<T> render
, Action<T> renderAlt) {//实现不相关});}
public static void Repeater<T>(this HtmlHelper html
, IEnumerable<T> items
, string className
, string classNameAlt
, Action<T, string> render) {//实现不相关});
}
}}
我已经在我的Web.Config中包含了以下内容:
<add namespace="MyAwesomeBlog.Helpers"/>这是我在视图中对扩展方法的使用:
<% HtmlHelper.Repeater<Post>(Model, "post", "post-alt", (post, cssClassName) => { %>
<div class="<%=cssClassName %>">
<h1><%= post.Title %></h1>
<p>
<%= post.Body %>
</p>
</div>
<% }); %>尽管如此,编译器还是在".Repeater“下面给出了弯弯曲曲的线条,告诉我HtmlHelper没有这样的方法。
我错过了什么?
发布于 2011-11-17 05:38:36
您是否将其添加到视图文件夹中的web.config或根Web.Config中?它需要放在“Views/web.config”中。
https://stackoverflow.com/questions/8159058
复制相似问题