bruceiow
bruceiow

Reputation: 327

retrieve username for two different ID's in same view

I am trying to get a list of linked users in to a MVC view & I am struggling!!!

Users table has an int ID and a varchar name

User Roles Table has int holderid, int officerid & int role id

Roles table has int id and varchar description

ID in users table is linked to both holder id & officer ID in user roles.

Role id is linked to id in roles

From my controller I am passing in one user ID to a strongly typed user role view. That view displays the name for the user id fine. Each user id will have multiple rows in user roles table, each with a different officer id.

My Issue

My issue lies in the fact that I cannot display the name from the users table that relates to an officer (or at least I can’t work out how to perform this in the view!! Or whether it should be done elsewhere in fact.)

Really what I want to do is say:

@Html.DisplayFor(modelItem => item.users.name.where(item.userid == item.officerid)

But this doesn’t seem to be working. I get this error: 'string' does not contain a definition for 'Where' and the best extension method overload Can anyone offer any advice??

Upvotes: 0

Views: 113

Answers (1)

Yasser Shaikh
Yasser Shaikh

Reputation: 47774

item.users.name is a string. And you cannot use where on it. Instead try something like this

item.users.Where(item.userid == item.officerid).FirstOrDefault().Name

Now here users is a table, hence a collection.

And are you working without Intellisense ?

Upvotes: 1

Related Questions