title: System.InvalidOperationException: The model item passed into the dictionary is of type
body: <p>I am writing a code that will create a object customer and display it </p>
  
  <p>Class1.cs is the model I am using:</p>
  
  <pre><code>using System;                       
  using System.Collections.Generic;                       
  using System.Linq;                      
  using System.Web;                       
  
  namespace WebApplication4.Models                        
  {                       
      public class Class1                     
      {                       
          public class Customer                       
          {                       
              public int Id { set; get; }                     
              public string CustomerCode { set; get; }                        
              public double Amount { set; get; }                      
  
  
          }                       
  
      }                       
  }                       
  </code></pre>
  
  <p>under Default1Controller I have :</p>
  
  <pre><code>using System;           
  using System.Collections.Generic;           
  using System.Linq;          
  using System.Web;           
  using System.Web.Mvc;           
  
  
  using WebApplication4.Models ;          
  
  
  namespace WebApplication4.Models            
  {           
      public class Default1Controller : Controller            
      {           
          //          
          // GET: /Default1/          
          public ActionResult Index()         
  
          {           
              Class1.Customer ob = new Class1.Customer();         
  
              ob.Id = 1001;           
              ob.CustomerCode = "C001";           
              ob.Amount = 900.23;         
              return View(ob);            
          }           
      }       
  }       
  </code></pre>
  
  <p>I right clicked ActionResult and added a view with the following code:</p>
  
  <pre><code>@model WebApplication4.Models.Class1
  
  @{
      ViewBag.Title = "Index";
  }
  
      &lt;html&gt;
  
  
      &lt;head&gt;
          &lt;title&gt;Title of the document&lt;/title&gt;
      &lt;/head&gt;
  
          &lt;body&gt;
  
              &lt;div&gt; 
                   The customer id is: &lt;% = | Model.Id %&gt;  &lt; br/&gt;
                   The customer Code  is: &lt;% = | Model.CustomerCode  %&gt;  &lt; br/&gt;
                   The customer Amount is: &lt;% = | Model.Id %&gt;  &lt; br/&gt;
  
              &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>When I run the code , i am getting :</p>
  
  <blockquote>
    <p>Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'WebApplication4.Models.Class1+Customer', but this dictionary requires a model item of type 'WebApplication4.Models.Class1'.</p>
  </blockquote>
  
  <hr>
  
  <p>ok, I took out the nestled class under Class1.cs, </p>
  
  <p>so now it only says public class Customer.</p>
  
  <p>and I also changed namespace WebApplication4.Models   </p>
  
  <p>to namespace WebApplication4.Controller under DefaultController1.cs,</p>
  
  <p>but when I go under Index.cshtml, it says</p>
  
  <p>The Type or namespace Class1 does not exist in the namespace WebApplication4.Models</p>