Search code examples
c#asp.net-mvc-4asp.net-mvc-viewmodel

MVC4 ViewModel System String Error


This is a common Error on SO but I seem not to be able to fix the error The model item passed into the dictionary is of type 'System.String', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[ITEye.ViewModels.IssueViewModel]'. Any help to troubleshoot will be appreciated

Viewmodel

 public class IssueViewModel
    {
        public int ItemId { get; set; }
        public string Name { get; set; }
        public string ItemLocation { get; set; }
        public string UserName { get; set; }
    }

Controller

public ActionResult Issueds()
        {
            var query = Issue();
            return View(query);
        }
        public IEnumerable Issue()
        {
            var issued = from item in db.Items
                        join issues in db.Issues on item.ItemId equals issues.ItemId
                        join users in db.Staffs on issues.StaffId equals users.StaffId
                        where issues.StaffId == users.StaffId

                         select new IssueViewModel()
                        {
                            ItemId = item.ItemId,
                            Name = item.ItemName,
                            ItemLocation = item.Location.LocName,
                            UserName = users.StaffName
                        };

            return issued.AsEnumerable();
}

View

@model IEnumerable<ITEye.ViewModels.IssueViewModel>
@foreach (var item in Model) {

<p>
   @item.Name
</p>

}

Solution

  • As sure as I was that the code was okay as I had researched wide on this, the problem turned out to be an error in the view. I used @{Html.RenderPartial("Issueds", "Issue");} instead of @{Html.RenderAction("Issueds", "Issue");}