저는 EPiServer를 처음 사용하며 작성한 뉴스 목록에서 하위 뉴스 기사 페이지를 검색하려고합니다. 온라인에서 찾은 예제는 Locate() 메서드를 사용했지만 코드에 Locate를 적용하려고 시도하면 찾을 수 없습니다.Locate()에 대한 EPiServer 7 네임 스페이스가 확인되지 않습니다.
이것은 내가 본 기사 중 하나입니다. http://world.episerver.com/Blogs/Johan-Bjornfot/Dates1/2012/8/EPiServer7-Working-with-IContentRepositoryDataFactory/
기본적으로 뉴스 항목 목록에 대해 하위 기사 목록 만 반환하면 시도하려는 방식이 처음부터 올바르지 않을 수 있습니다.
어쨌든, 이것은 using 문을 사용하는 현재 모델입니다.
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.ServiceLocation;
using EPiServer.SpecializedProperties;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace EPiServerExercise.Models.Pages
{
[ContentType(DisplayName = "News List", GUID = "ac3287b1-4d78-4eb3-bad2-6b5c43530b33", Description = "")]
public class NewsList : BasePage
{
private IEnumerable<NewsArticle> getNewsArticles(NewsList currentPage)
{
//var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>
//IEnumerable<NewsArticle> newsArticles = new List<NewsArticle>();
//PageReference pageLink = currentPage.ParentLink;
//IEnumerable<NewsArticle> newsArticles = Locate.ContentRepository().GetChildren<IContent>(pageLink);
//IEnumerable<NewsArticle> newsArticles = ServiceLocationHelperExtensions.
//var serviceLocationHelper = ServiceLocator.Current.GetInstance();
//serviceLocationHelper.ContentLoader
}
}
}
무엇 참조하면 나는이 해결하기 위해() 메소드를 찾습니다 얻을 수없는 무엇입니까? 우리는 EPiServer 7과 MVC를 사용하고 있습니다. 당신의 도움을 주셔서 감사합니다. 2014년 11월 18일
에
업데이트이 내가 모델로 넣어 최종 솔루션입니다. Vsevolod Goloviznin이 제안한 것과 거의 동일합니다. 감사. 그는 단지 IContentRepository
을 얻을 수있는 공장을 사용하고 언급하는 것을 잊었다처럼
public string showNewsArticles()
{
IEnumerable<NewsArticle> newsArticles = getNewsArticles(this);
// Code to loop through the articles
}
private IEnumerable<NewsArticle> getNewsArticles(NewsList currentPage)
{
var repository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
IEnumerable<NewsArticle> newsArticles = repository.GetChildren<NewsArticle>(currentPage.ContentLink);
return newsArticles;
}
감사합니다! 당신이 쓴 것은 질문을 올린 후 글을 쓰는 것과 매우 흡사합니다. –