title: How to pass an array from main view to partial view in asp.net mvc 5
body: <p>I've a main view that contains an array received from the corresponding Action and it also contains a partial view reference below</p>
  
  <p><strong>Create.cshtml</strong> :</p>
  
  <pre><code>@model HrAndPayrollSystem.Models.EmployeeMasterA
  
  @using (Html.BeginForm())
  {
      ViewData["fs_lbls"] = ViewBag.FS_lbls as string[];
      @Html.Partial("~/Views/EmployeeMasterA/FinalSettlementTAB.cshtml", Model)
  }
  </code></pre>
  
  <p>and the referenced partial view above is defined below</p>
  
  <p><strong>FinalSettlementTAB.cshtml</strong> :</p>
  
  <pre><code>@model HrAndPayrollSystem.Models.EmployeeMasterA
  
      @Html.DropDownList("DeptId", null, "Department")   
  
  /* Print "ViewData["fs_lbls"]" array defined in the Main View `Create.cshtml` here */
  </code></pre>
  
  <p>I've an array defined in the <code>Create.cshtml</code>, now, I want to pass it into the partial view <code>HR_EmployeeFinalSettlementTAB.cshtml</code> and print it, What is the proper way to to this?</p>
  
  <p>What I've tried :</p>
  
  <p>I changed the <code>@Html.Partial()</code> line into below :</p>
  
  <pre><code> @Html.Partial("~/Views/EmployeeMasterA/FinalSettlementTAB.cshtml", null, new ViewDataDictionary { { "fs_lbls", ViewData["fs_lbls"] } })
  </code></pre>
  
  <p>and modified the FinalSettlementTAB.cshtml file as below :</p>
  
  <pre><code>@model HrAndPayrollSystem.Models.EmployeeMasterA
  
  @Html.DropDownList("DeptId", null, "Department")   
  
  @foreach (var i in ViewData["fs_lbls"] as string[])
  {
      @i
  }
  </code></pre>
  
  <p>But it throws an exception <code>InvalidOperationException</code> at line <code>@Html.DropDownList("DeptId", null, "Department")</code> by saying : </p>
  
  <blockquote>
    <p>There is no ViewData item of type 'IEnumerable' that has the key 'DeptId'.</p>
  </blockquote>
  
  <p>It throws the above exception whenever I try to pass the array data to the partial view using <code>ViewDataDictionary</code>, otherwise, it is working fine, when I'm not.</p>
  
  <p>How do I get rid of the above exception and properly pass array data from main view to the partial view?</p>