0
votes

Hi I am very new to mvc and need help I created this

public ActionResult Index()
        {
            var joblist = (from s in _entities.TaleoJobs
                           group s by new { s.JobTitle}
                               into myGroup
                               where myGroup.Count() > 0
                               select new { myGroup.Key.JobTitle }
                               );
            return View(joblist.ToList()); 
        }

but when I create the view I get the following error

The model item passed into the dictionary is of type 'System.Collections.Generic.List1[<>f__AnonymousType01[System.String]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[careers.TaleoJobs]'.

Here is the code for the view

*@model IEnumerable<careers.TaleoJobs>
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>

        <th>
            JobTitle
        </th>

    </tr>
@foreach (var item in Model) {
    <tr>

        <td>
            @Html.DisplayFor(modelItem => item.JobTitle)
        </td>

    </tr>
}
</table>*

I would be grateful if anyone can help - tried looking at other examples but i am at a loss.

1

1 Answers

2
votes

When you are selecting the list, you are only selecting the JobTitle, which is a string. So your list is indeed a List<string>.

You can either update your select to select the entire object:

var joblist = (from s in _entities.TaleoJobs
                           group s by new { s.JobTitle}
                               into myGroup
                               where myGroup.Count() > 0
                               select s
                               );

Or, keep your current select and update the type of the view to:

IEnumerable<string>