title: Passing object containing object from model to view in ASP.NET
body: <p>Usin ASP.NET I am trying to add a list of profiles to a object in a model and then enumerate over this list in the view.</p>
  
  <pre><code>     public ActionResult Index(BlogPage currentPage)
      {
          var model = new BlogPageModel(currentPage);
  
          var pages = new List&lt;BlogPage&gt;();
  
          var profilePages = new List&lt;ProfilePage&gt;();
          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);
      }
  </code></pre>
  
  <p>Using this code in the view:</p>
  
  <pre><code>   @foreach (ProfilePage profile in Model.BlogPages)
              {
              @Html.Partial("../ProfilePage/Index", new PageViewModel&lt;ProfilePage&gt;(profile))
              }
  </code></pre>
  
  <p>However above code returns the error:</p>
  
  <p><code>CS0030: Cannot convert type 'Models.Pages.BlogPage' to 'Models.Pages.ProfilePage'</code></p>
  
  <p>Can someone point me the correct way to store a list inside a model and render this nested object in a view?</p>
  
  <p>Thanks!</p>