0

I have two data sources i am working with, my Database which contains UserCode and JobCode and my WCF Service which contain JobCode and JobDescription. What i am trying to get it select a User from my DB and all the JobCodes linked to that User will be displayed in the View, But instead of the JobCode being displayed i want to display the JobDescription.

So at the minute my View returns UserCodes and JobCodes from my DB but i need it to display the JobDescription associated with the JobCode. Can anyone help me out??

 public ActionResult Index(String UserCode)
 {
    var getUser = db.UserJobs.Where(s => s.UserCode == UserCode);            
    var allJobs = jobsWCF.getAllJobs();

    var jobList = allJobs.Join(getUser, s => s.jobCode, ss => ss.jobCode, (s, ss) => s.jobDescription);

    return View(jobList);
}

This is the error i keep getting back:

The model item passed into the dictionary is of type 'System.Linq.Enumerable+<JoinIterator>d__61`4[JobsDTO, UserJob,System.String,System.String]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[UserJob]'. 
Bean Shares
  • 49
  • 1
  • 6

1 Answers1

1

It seems that type of jobList doesn't match the type of Model defined in View. You may change view's Model type to List<string>,in the controller change return line to return View(jobList.ToList());

Zen
  • 621
  • 4
  • 11
  • To change the view model type do you mean the method type?? – Bean Shares Jan 23 '16 at 16:30
  • @BeanShares Typically, view model type is defined in viewName.cshtml file, refer to this so question for more detail http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc – Zen Jan 23 '16 at 17:51