title: Hi, I am Using Expando Object to List two different model data on a View in Asp.net core Mvc, But I also want link a model named comments to sameView
body: <p><strong>Error:</strong>
  <em><strong>InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'System.Dynamic.ExpandoObject', but this ViewDataDictionary instance requires a model item of type 'MyProject.Models.Comments'.</strong></em></p>
  <p>This is My ViewResult:</p>
  <pre><code>
      private RecepieDbContext _recepie;
      private UserDbContext _usr;
      private CommentsDbContext _cmnt;
      
      
          public RecepieController(RecepieDbContext contx,UserDbContext usr,CommentsDbContext cmntObj)
          {
              _recepie=contx;
              _usr=usr;
              _cmnt = cmntObj;
      
          }
      public ViewResult Details(int id)
          {
              dynamic mymodel = new ExpandoObject();
              var det = _recepie.Recepies.Find(id);
              var user = _usr.Users.Find(det.UserId);
              mymodel.Recepie=det;
              mymodel.User=user;
              return View(mymodel);
          }
  
  </code></pre>
  <p>This is My View Code named Details.cshtml:</p>
  <pre><code>
      @* @model MyProject.Models.Recepie *@
      @* @using MultipleModelInOneView; *@
      @model dynamic
      
      @{
          Layout=&quot;_RecepieLayout&quot;;
      }
      
      &lt;div class=&quot;row&quot;&gt;
              &lt;div class=&quot;col-md-5 col-sm-12&quot; &gt;
                  &lt;img src=&quot;~/Images/fishsoup.jpg&quot; style=&quot;max-width:500px;&quot;/&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-md-7&quot;&gt;
                  &lt;h1&gt;
                      @Model.Recepie.Category
                  &lt;/h1&gt;
                  &lt;p&gt;
                      @Model.Recepie.name
                  &lt;/p&gt;
                  &lt;p&gt;
                      Created by @Model.User.name
                  &lt;/p&gt;
                  &lt;p&gt;
                      @Model.Recepie.Description
                  &lt;/p&gt;
                  &lt;p&gt;
                      @Model.Recepie.Ingredients
                  &lt;/p&gt;
      
              &lt;/div&gt;
      &lt;/div&gt;
      
      &lt;partial name=&quot;Comments&quot; /&gt;
  
  </code></pre>
  <p>And This is The Partial View fpr comments:</p>
  <pre><code>
      @model MyProject.Models.Comments
      &lt;div class=&quot;container&quot;&gt;
          &lt;form&gt;
              &lt;label asp-for=&quot;name&quot;&gt;&lt;/label&gt;
              &lt;input asp-for=&quot;name&quot; type=&quot;text&quot;/&gt;
              &lt;label asp-for=&quot;email&quot;&gt;&lt;/label&gt;
              &lt;input asp-for=&quot;email&quot; type=&quot;text&quot;/&gt;
              &lt;label asp-for=&quot;Comment&quot;&gt;&lt;/label&gt;
              &lt;input asp-for=&quot;Comment&quot; type=&quot;text-area&quot;/&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  
  </code></pre>