title: Using two model classes in one view MVC3
body: <p>Here is the scenario. I have made a parent model class to use two model classes in one     view. That works fine but when I try to get a record from by database, I get this error. The model item passed into the dictionary is of type 'PMS_V2.Models.Pension_info', but this dictionary requires a model item of type 'PMS_V2.Models.Parentmodel'.</p>
  
  <p><b>Parentmodel.cs</b></p>
  
  <pre><code>namespace PMS_V2.Models {
    // it  is the class of the parent model
    public class Parentmodel {
      // calling of pension info
      // for using foreach I have used ienumerable
      public IEnumerable&lt;Pension_info&gt; pension_infos { get; set; }
      //constructor
      public Parentmodel() {
        pension_infos = new List&lt;Pension_info&gt;();
      }
      // class of search
      public Search id { get; set; } // method to get id
    }
  }
  </code></pre>
  
  <p><b>Search.cshtml</b>    </p>
  
  <pre><code>@model PMS_V2.Models.Parentmodel
  @{
    ViewBag.Title = "Search";
  }
  &lt;h2&gt;Search&lt;/h2&gt;
  &lt;p&gt; Here Pensioner can check his records. Give your Pension_id in search query and get your details.&lt;/p&gt;
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;  &lt;/script&gt;
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"    type="text/javascript"&gt;&lt;/script&gt;
  @using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    &lt;fieldset&gt;
      &lt;legend&gt;Pension_info&lt;/legend&gt;
      &lt;div class="editor-label"&gt;
        @Html.LabelFor(model =&gt; model.id, "Pension_no")
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
        @Html.TextBoxFor(model=&gt;model.id)  // getting id from user..
        @Html.ValidationMessageFor(model=&gt;model.id)
      &lt;/div&gt;
      &lt;p&gt;
        &lt;input type="submit" value="Search" /&gt;
      &lt;/p&gt;
    &lt;/fieldset&gt;
  }
  &lt;table&gt;
    @foreach (var item in  Model.pension_infos) {
    // model, I think the problem is here
      var i = 0;
      if (i == 0) {
        i++;
        &lt;tr&gt;
          &lt;th&gt;Pension_id&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;P_month&lt;/th&gt;
          &lt;th&gt;Amount&lt;/th&gt;
        &lt;/tr&gt;
      }
      &lt;tr&gt;
        &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Pen_id)&lt;/td&gt;
        &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Pensioner.Name)&lt;/td&gt;
        &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.P_month)&lt;/td&gt;
        &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Amount)&lt;/td&gt;
      &lt;/tr&gt;
    }
  &lt;/table&gt;
  </code></pre>
  
  <p><b>Pension_infoController.cs</b></p>
  
  <pre><code>[HttpPost]
  public ActionResult Search(string id) {
    var abc = from m in db.Pension_info
    // Linq query to get records
      where m.Pen_id == id
      select m;
      return View(abc.FirstOrDefault());
  }
  </code></pre>
  
  <p>Please help me... I have googled it a lot...</p>