0

私は EPiServer を初めて使用し、作成したニュース リストから子ニュース記事ページを取得しようとしています。オンラインで見つけた例では Locate() メソッドを使用していましたが、自分のコードに Locate を適用しようとすると、見つかりませんでした。

これは私が見た記事の1つです。 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

        }

    }
}

Locate() メソッドを解決するために欠落している参照は何ですか? EPiServer 7 と MVC を使用しています。ご協力いただきありがとうございます。

2014 年 11 月 18 日の更新

これが、私がモデルに入れた最終的な解決策です。Vsevolod Goloviznin が提案したものとほぼ同じです。ありがとう。

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;
}
4

1 に答える 1

1

彼は工場を使用して取得IContentRepositoryし、言及するのを忘れているようです。したがって、同じ機能を取得するには、 を使用してServiceLocatorを取得しIContentRepository、ページのすべての子を取得できます。

var service = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
var pages = service.GetChildren<NewsArticle>(currentPage.ParentLink).ToList();
于 2014-11-17T22:24:41.527 に答える