title: MVC3 Strongly typed partial view model binding
body: <p>I have a strongly typed view, Edit, with a model named OrderModel.  In this view, I am using a strongly typed partial view that has a model named OrderTypeModel. The partial view, _OrderTypeAutoComplete, that contains a jqueryui autocomplete textbox.  If I render the view with this code,</p>
  
  <pre><code>public ActionResult Edit(){
      return View();
  }
  </code></pre>
  
  <p>My Edit view contains the following Razor markup</p>
  
  <pre><code>&lt;div class="editor-field"&gt;
      @Html.Partial("_OrderTypeAutoComplete")
      @Html.HiddenFor(model =&gt; model.OrderTypeID)
      @Html.ValidationMessageFor(m =&gt; m.OrderTypeID)
  &lt;/div&gt;
  </code></pre>
  
  <p>My Partial view contains this razor markup</p>
  
  <pre><code>@{
      Layout = null;
  }
  &lt;script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  @Html.AutoCompleteFor(model =&gt; model.OrderTypeID, x =&gt;  x.OrderType, "Items","Orders")
  </code></pre>
  
  <p>When I render this, all is great and my autocomplete works great (using an auto-complete extension). Anyway, I needed to initialize something in my initial OrderModel, so I changed the code in my controller to this.</p>
  
  <pre><code>public ActionResult Edit(){
      return View(OrderService.GetInitializedOrderModel()); //returns a new OrderModel
  }
  </code></pre>
  
  <p>Now when I render the view, I get the exception:
  The model item passed into the dictionary is of type 'Testing.Models.OrderModel', but this dictionary requires a model item of type 'Testing.Models.OrderTypeModel'.</p>
  
  <p>on this line in my view
      @Html.Partial("_OrderTypeAutoComplete")</p>
  
  <p>It seems the Razor engine will create the OrderModel for the view and the OrderTypeModel for the partial view fine when I haven't supplied the OrderModel.  This will give the same results.</p>
  
  <pre><code>public ActionResult Edit(){
      return View(new OrderModel())
  }
  </code></pre>
  
  <p>I'm new to MVC so I'm not sure what's going on here.  I'm simply trying to provide some simple dropdown values for my view in the OrderModel model that are small enough that I don't require a jquery postback to get. That's the values I'm initialing in my model for the Http Get on my Edit action.</p>
  
  <p>Any help would be appreciated.  Thanks.</p>