title: How Can I Get ViewData in PartialView in Razor Pages
body: <p>I'm Using Razor Pages For my App, in one part of my app I've used a partial view here is my codes;</p>
  
  <pre><code> public class Permission
      {
          [Key]
          public int PermissionId { get; set; }     
          public string PermissionTitle { get; set; }
          public int? ParentID { get; set; }       
      }
  
    public class IndexModel : PageModel
      {
       public PartialViewResult OnGetCreateRole()
      {
          var ListPermission = permissionService.AllPermission();
          return new PartialViewResult()
            {
              ViewName = "_PCreateRole", // partial's name
              ViewData = new ViewDataDictionary&lt;List&lt;Permission&gt;&gt;(ViewData, 
              ListPermission)
            };
      }
      }
  </code></pre>
  
  <p><code>ViewData</code> is a List of <code>Permission</code> class and i've sent ViewData to partial but i dont know how to get <code>ViewData</code>, also my partial use another <code>model</code>, below is my partial:</p>
  
  <pre><code>@model ToMVC.DataLayer.Entities.User.Role
  &lt;div class="row"&gt;
      &lt;div class="col-md-12"&gt;
          &lt;form asp-page="CreateRole" method="post"&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="control-label"&gt;Title&lt;/label&gt;
                  &lt;input asp-for="RoleTitle" class="form-control"/&gt;
                  &lt;p&gt;&lt;span class="text-danger" asp-validation-for="RoleTitle"&gt;&lt;/span&gt;&lt;/p&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;input type="submit" value="submit" class="btn btn-primary" /&gt;
              &lt;/div&gt;
  
             //this part needs ViewData 
             @foreach (var item in ViewData)
              {
  
              }
  
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I want to use <code>ViewData</code> in <code>Foreach</code> loop.</p>