When trying to use an IEnumerable model in a view, and returning a List() from the controller I get the following error:
The model item passed into the ViewDataDictionary is of type 'System.Collections.Generic.List`1[DefaultWeb.Models.DefaultWebSite.Source]', but this ViewDataDictionary instance requires a model item of type 'DefaultWeb.Models.DefaultWebSite.Source'.
It is not a type mismatch! I've seen many post regarding this error, but not specifically addressing this issue
//Controller
public IActionResult Main() { return PartialView(_context.Sources.ToList()); } // PartialView Main @model IEnumerable<Source> @using System.Collections.Generic;<div id="comments-mgr" class="card"> . . @foreach (var item in Model ) { . . @Html.DisplayFor(modelItem => item.Name) ...... . } . .</div>
I know with Razor @RenderPartial, you need to define the ViewDataDictionary, but with "return PartialView()"; from a Controller there is no such option.
I am using project hosting and not IISExpress, Also using the current version of VS2017 15.2 26430.15 and have updated all the packages...
Any ideas? Thanks!