2017-06-08 11 views
0

親コントローラから子オブジェクトのコレクションを繰り返し処理しようとしています。子の内部のIListからデータを取得するViewModel

public class ListBlogsPageModel : IPageViewModel<ListBlogsPage> 
{ 
    public IList<BlogPage> BlogPages { get; set; } 
} 

BlogPagesには、BlogPageのインデックスが含まれています。このBlogPageモデルには、親コントローラで繰り返したいProfilePageのIListが含まれています。

public class BlogPageModel : IPageViewModel<BlogPage> 
{ 
    public IList<ProfilePage> Profiles { get; set; } 
} 

私の質問は、親ListBlogsPageのこの子プロファイルモデルにどうやってアクセスするのですか?プロファイルをBlogPageの子どもたちと同じ方法で取得しようとしましたが(下記参照)、値を受け取っていないようです。

public ActionResult Index(ListBlogsPage currentPage) 
{ 
    var model = new ListBlogsPageModel(currentPage); 
    var blogPages = _contentLoader.GetChildren<BlogPage>(currentPage.ContentLink).ToList(); 
    var authorPages = _contentLoader.GetChildren<ProfilePage>(currentPage.ContentLink).ToList(); 
    var filteredPages = _contentFilterService.FilterForDisplay(blogPages, false, true).ToList(); 
    var filteredAuthors = _contentFilterService.FilterForDisplay(authorPages, false, true).ToList(); 
    model.BlogPages = filteredPages; 
    model.AuthorPages = filteredAuthors; 
    return View(model); 
} 

答えて

0
foreach (page in model.BlogPages) 
{ 
    page.Profiles = something; 
} 

私が間違っている可能性がありますが、これを尋ねたように思えます。

+0

ありがとうございます!このコードはインデックスコントローラ向けですか?それとも、プロファイルを使ってビューをレンダリングするのですか? – dwigt

+0

これはどこでも使用できますが、この場合はコントローラ用です。 –

関連する問題