I am working in AspNetCore 1.1. I have reviewed my code in my controller and view several times to make sure I am calling the correct model type.
Controller
public IActionResult Index() { List<NameDto> nameList = new List<nameDto>(); nameList = _iNames.ListAllNames(); return View(nameList); }
View
@model List<nameDto> foreach (var item in Model) { <div>@item.Name</div> }
Very simple piece of code, however when the view trys to load I get the error
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'System.Collections.Generic.List`1[NameDto]', but this ViewDataDictionary instance requires a model item of type 'System.Collections.Generic.IEnumerable`1[HouseDto]'.
I have declared @model List<nameDto> but it is looking for a completely different model type. I will even navigate to a completely different page and I get the same error stating it requires a model type of HouseDto. Seems like the ViewDataDictionary is not clearing itself and it is holding on to the reference to HouseDto. I can load the page if I don't pass data to the view. Only page that works is the page I have declared HouseDto as the model type.
My code was working just fine until this error started to pop-up.
Any insight is very appreciated.
Brad