좋아, Phil Haack의 블로그에서 설명한대로 HtmlHelper에 대한 Repeater 확장 메서드를 구현하려고합니다. http://haacked.com/archive/2008/05/03/code-based-repeater-for-asp.net-mvc.aspx 그러나 내보기에서 사용하려고하면 컴파일 오류 'System.Web.Mvc.HtmlHelper'에 'Repeater'에 대한 정의가 없습니다. 여기 Asp.Net MVC HtmlHelper 확장 메서드가 표시되지 않습니다.
내 확장 클래스 :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) {
// 구현 무관 }); 이것은 내보기에서 확장 메서드 내 사용하는 것입니다
<add namespace="MyAwesomeBlog.Helpers"/>
: :이 내있는 Web.Config 포함했다
}
}
} 여전히
<% HtmlHelper.Repeater<Post>(Model, "post", "post-alt", (post, cssClassName) => { %>
<div class="<%=cssClassName %>">
<h1><%= post.Title %></h1>
<p>
<%= post.Body %>
</p>
</div>
<% }); %>
을, 컴파일러는 ".Repeater"아래에 HtmlHelper에 그러한 메소드가 없다는 것을 알리는 구불 구불 한 라인을 제공합니다.
내가 무엇을 놓쳤는가?
나는 당신의 대답이 정확히 맞았다는 것을 알았을 때 나는 그것을 알아 냈고 내 자신의 질문에 답하기 위해 다시오고있었습니다 ... 그것은 HtmlHelper가 아니라 Html.Repeater를 호출해야한다는 것이 드러났습니다. Repeater. –