COURSE of the MONTH

Want to display associated name with an Id.

I have a problem displaying the desired data instead of the default data built by mvc on an index page. I have a User class, a Mentorship class, and a Project class. The trick is that the User table contains all of the users, both users and mentors, as seen in the Mentorship class. In this case the MentorID is simply the UserID. Yes it would be alot easier to use two tables, however, because the user data is imported from an external data source I am told that using two tables will not be permitted. When I display the Mentorship Index page I need to display an actual name in both the UserID column and the MentorID column. The UserID part has been fairly easy to accomplish, displaying the FullName based on associated ID for the MentorID has been elusive. How do I accomplish this?Mentor.pdf

In the Mentorship Index View, the second column item displays as an integer, MentorID, what I would like to display is the FullName that is associated with that MentorID. The MentorID in the Mentorship Table has a corresponding UserID in the User Table such that Mentorship.MentorID = User.UserID. How can I display the FullName from the User Table that corresponds to the MentorID instead of the MentorID? I am new to C# and MVC so it is possible that my MentorshipConfiguration is either incorrect and/or incomplete to properly represent this unique relationship. Getting the FullName associated with the UserID to display in column 1 was an easy task, this one has been an exercise in frustration so far. Thank you for your time and assistance.Error2.jpg

Check my last comment. I edited it apparently after you looked at it. I had the MentorName function inside the modelItem, which is wrong. It now shows the entire modeItem instance of MentorID inside the MentorName function. this should pass the id to your function and return the name.

0

jkmlgnAuthor Commented: 2013-01-29

Error of MentorName does not exist in the current context. Screenshot of error attached.MentorName-Error.jpg

You have a User defined as a parameter in you Mentorship model, so you should be able to call up the Fullname string from the User associated with the Mentor.

@Html.DisplayFor(modelItem =>item.MentorID.User.FullName)

0

jkmlgnAuthor Commented: 2013-01-29

That's what I thought, because of the navigation this should be a simple solution, however looks are apparently deceiving. I have been dancing around this for two weeks and here I am. It is proving to be an elusive solution. Error file attached.UserError.jpg

0

jkmlgnAuthor Commented: 2013-01-29

I have attached a screen shot of the User Index View, perhaps this may be helpful.UserIndex.jpg

User is already associated with a MentorID for each modelItem, isn't it?

@Html.DisplayFor(modelItem =>item.User.FullName)

0

jkmlgnAuthor Commented: 2013-01-29

In regards to Mentorship yes, a user is not required to have a Mentor, a user can have multiple Mentors, a Mentor must have a User. The Mentorship relationship involves two users from the User Table, one that will be Mentorship.UserID and another one that will be Mentorship.MentorID. Only a student can be Mentorship.UserID and only a Faculty can be Mentorship.MentorID. While a Faculty has not entered into a Mentorship relationship they remain a User and not a User/Mentor. Your previous post does indeed produce the FullName of the User that is the Mentorship.UserID portion of the relationship, that much I was able to produce on my own. Now, getting the FullName of the User which is the Mentorship.MentorID that is a trick. Note that the Mentorship.MentorID will be identical to an existing Faculty UserID, which of course means that the Mentorship.UserID will be identical to an existing Student UserID. Please not the subtle differences between the User Index and the Mentorship Index screen shots. The Students are the User in the Mentorship View, the displayed Integer under the Mentor heading are the Mentorship.MentorID, this is also the User.UserID of a Faculty User. While I know this is an odd data model, when a new user logs in their profile is 'imported' from an external data source, it is because of this data source that all users must remain in one table and has created this scenario.

Unfortunately neither am I, most of my experience has been process control programming with a little bit of VB, VB.Net, and occasional SQL. I have tried to go at this utilizing a SQL WHERE statement but to no avail. Attached is the current error, cannot use as a method.User-Method-Error.jpg

0

jkmlgnAuthor Commented: 2013-01-30

I have found a major flaw in the database model, am currently attempting to re-design the data model so for now this question is a moot issue. Thank you for your time and assistance.