title: MVC Create A Partial View In A Modal
body: <p>So I have a partial view called _CreateClient that needs to be passed a ClientEditViewModal that should get passed from the controller like so:</p>
  
  <pre><code>    public ActionResult Create()
      {
          ClientEditViewModel viewModel = new ClientEditViewModel();
          return PartialView("_CreateClient", viewModel);
      }
  </code></pre>
  
  <p>But in my Index view I need to call the partial as a modal window and I am doing it like this:</p>
  
  <pre><code>&lt;div class="mfp-hide"&gt;   
      @Html.Partial("_CreateClient")
  &lt;/div&gt;
  </code></pre>
  
  <p>However my Index view needs to take an IEnumerable of ClientModel and I am getting this error when I try to render the Index view:</p>
  
  <pre><code>The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery`1[Project.Models.ClientModel]', but this dictionary requires a model item of type 'Project.ViewModels.ClientEditViewModel'.
  </code></pre>
  
  <p>How do I get the view passed to the _CreateClient and keep it in the modal? Or is there a better way to go about doing this?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>Index Action:</p>
  
  <pre><code>public ActionResult Index()
  {
      IEnumerable&lt;ClientModel&gt; clients = clientService.GetAll();
      return View(clients);
  }
  </code></pre>
  
  <p>Index View:</p>
  
  <pre><code>@model IEnumerable&lt;TechUCRM.Models.ClientModel&gt;
  @{
      Layout = "~/Views/Shared/_UserLayout.cshtml";
      ViewBag.Title = "Index";
  }
  
  @section alert {
      @if (!String.IsNullOrEmpty(ViewBag.alert))
      {
          &lt;div class="alert alert-@ViewBag.alertType" role="alert"&gt;
              @ViewBag.alert
          &lt;/div&gt;
      }
  }
  &lt;div class="row"&gt;
      &lt;div class="col-sm-6 text-left"&gt;
          &lt;h2&gt;Clients&lt;/h2&gt;
      &lt;/div&gt;
  
  
      &lt;div class="col-sm-6 text-right"&gt;
          &lt;label for="#add-client-btn"&gt;New Client&lt;/label&gt;
          &lt;a href="@Url.Action("Create")" id="add-client-btn" class="btn btn-default btn-sm"&gt;&lt;i class="fa fa-plus fa-fw"&gt;&lt;/i&gt;&lt;/a&gt;
  
      &lt;/div&gt;
  
  
      &lt;div class="mfp-hide"&gt;  
          @Html.Partial("_CreateClient") &lt;!--Need to be passed ClientCreateViewModel--&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  
  
  &lt;div class="row"&gt;
      @foreach(var item in Model)
      {
          &lt;div class="col-md-3 col-xs-12" style="margin-top:20px;"&gt;
              &lt;a href="" class="btn btn-primary btn-lg"&gt;@item.Name&lt;/a&gt;
          &lt;/div&gt;
      }
  &lt;/div&gt;
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Ok so I figured it out... I feel a little ridiculous because all I needed to do was to give the partial a new ViewModal... yep</p>
  
  <p>ANSWER:</p>
  
  <pre><code>@Html.Partial("_CreateClient", new ClientCreateViewModal()) 
  </code></pre>