Bean Shares
Bean Shares

Reputation: 49

Linking my WCF and my DB to return a View MVC C#

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]'. 

Upvotes: 0

Views: 55

Answers (1)

Zen
Zen

Reputation: 631

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());

Upvotes: 1

Related Questions