Usin ASP.NETモデルのオブジェクトにプロファイルのリストを追加し、このリストをビューに列挙しようとしています。しかし、上記のコード ASP.NETのモデルからオブジェクトへのオブジェクトの受け渡し
@foreach (ProfilePage profile in Model.BlogPages)
{
@Html.Partial("../ProfilePage/Index", new PageViewModel<ProfilePage>(profile))
}
がエラーを返した
:ビューにこのコードを使用して public ActionResult Index(BlogPage currentPage)
{
var model = new BlogPageModel(currentPage);
var pages = new List<BlogPage>();
var profilePages = new List<ProfilePage>();
if (currentPage.ProfileArea != null)
{
foreach (LinkItem linkItem in currentPage.ProfileArea)
{
var page = _pageDataHelper.GetPageData(linkItem);
var profilePage = page as ProfilePage;
if (profilePage != null)
{
profilePages.Add(profilePage);
}
}
model.Profiles = profilePages;
}
return View(model);
}
CS0030: Cannot convert type 'Models.Pages.BlogPage' to 'Models.Pages.ProfilePage'
誰かが私に内部のリストを格納するための正しい方法を指すことができますこのネストされたオブジェクトをビューでモデル化してレンダリングしますか?
ありがとうございます!
ProfilePage/IndexのモデルはProfilePageですか?それを確認しましたか? –
'Model.Profiles'を' foreach'したいと思っています –
あなたは 'Model.BlogPages'をループしています。これは上記のスニペットの中のそのプロパティへの唯一の参照です – Jonesopolis