Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Looking at your error message your view is expecting an <code>IEnumerable</code> which contains classes of <code>Project.Models.NewModel</code> where as your passing a <code>List</code> containing classes of <code>Project.Models.Movie</code>. Basically your passing your view data it's not designed to deal with. You can either change your view/partial at the top to read something like:</p> <pre><code>@model List&lt;Project.Models.Movie&gt; </code></pre> <p>This sets you view to expect a list of moives which is what your passing your view from your controller in the example. On a side note</p> <pre><code>@model IEnumerable&lt;Project.Models.Movie&gt; </code></pre> <p>would work as well as a <code>List</code> inherits from IEnumerable.</p> <p>If you want the view to accept an <code>IEnumerable&lt;Project.Models.NewModel&gt;</code> then you need to modify your controller to something like: (I'm making assumptions about your model properties here)</p> <pre><code>public ViewResult Index() { return View(db.Movies.Select(m =&gt; new NewModel { Title = m.Title, Director = m.Director})); } </code></pre> <p>This will then pass an <code>IEnumerable&lt;Project.Models.NewModel&gt;</code> to you view.</p> <p>On another note a simpler way to reference partials in razor is:</p> <pre><code>@Html.Partial("_NewPartialView") </code></pre> <h2>Update</h2> <p>You need to create yourself a <code>ViewModel</code> so it will look something like this:</p> <pre><code>public class IndexViewModel { public List&lt;Movie&gt; Movies {get; set;} public List&lt;NewModel&gt; NewModels {get; set;} } public ViewResult Index() { var viewModel = new IndexViewModel { Movies = db.Movies.ToList(), NewModels = new List&lt;NewModel&gt;() // Or however you populate it }; return View(viewModel ); } </code></pre> <p>Then in your view it will be something like this for your movies</p> <pre><code>@foreach (var moive in Model.Movies) { } </code></pre> <p>and you new model partials will be</p> <pre><code>@Html.Partial("_NewPartialView", Model.NewModels) </code></pre> <p>Note you will need to update your model at the top of the index page to reference IndexViewModel.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload