Solved

Want to display associated name with an Id.

Posted on 2013-01-29
25
205 Views
Last Modified: 2013-03-18
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
0
Comment
Question by:jkmlgn
  • 15
  • 10
25 Comments
 
LVL 8

Expert Comment

by:Barry62
Comment Utility
So you want your page to look like the pdf you attached, or is that what it is now and you need it to be different?

Please give us the code for your classes so we can better help you with this.
0
 

Author Comment

by:jkmlgn
Comment Utility
That is what I have now, I wish for the Mentor column to display a full name and not an Id number.  The models, controller, and view are attached as a pdf.
0
 

Author Comment

by:jkmlgn
Comment Utility
Let's try this again to attach file.  Does the attached pdf provide the information you requested?
Mentorship2.pdf
0
 
LVL 8

Expert Comment

by:Barry62
Comment Utility
I may be wrong, but I would say, without seeing your data structure, that you need to replace

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

with

@Html.DisplayFor(modelItem => item.mentorship.MentorID.fullName)
0
 

Author Comment

by:jkmlgn
Comment Utility
If by data structure you are refering to the Model classes they were included in the attached file.  Were you unable to view the pdf attachment?
0
 
LVL 8

Expert Comment

by:Barry62
Comment Utility
No, I was able to see it, but what I meant was your table structures - i.e. Users and Mentorships.

Please try my suggestion.  I think it will work.
0
 

Author Comment

by:jkmlgn
Comment Utility
Will let you know how it works out
0
 

Author Comment

by:jkmlgn
Comment Utility
Produced an error.
Error.jpg
DataStructure.jpg
0
 
LVL 8

Expert Comment

by:Barry62
Comment Utility
@Html.DisplayFor(MentorName(modelItem =>item.MentorID))
0
 

Author Comment

by:jkmlgn
Comment Utility
That generated a similar error, displayed in attachment.

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
0
 
LVL 8

Expert Comment

by:Barry62
Comment Utility
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
 

Author Comment

by:jkmlgn
Comment Utility
Error of MentorName does not exist in the current context.  Screenshot of error attached.
MentorName-Error.jpg
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 8

Assisted Solution

by:Barry62
Barry62 earned 400 total points
Comment Utility
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
 

Author Comment

by:jkmlgn
Comment Utility
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
 

Author Comment

by:jkmlgn
Comment Utility
I have attached a screen shot of the User Index View, perhaps this may be helpful.
UserIndex.jpg
0
 
LVL 8

Expert Comment

by:Barry62
Comment Utility
Try taking out the .MentorID before .User

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



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

Author Comment

by:jkmlgn
Comment Utility
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.
0
 
LVL 8

Expert Comment

by:Barry62
Comment Utility
OK, as you can probably tell, I am not a C# expert, but I do know Java, so I am trying to translate things in my head as I go.  Here is an idea:

Could you call for the Fullname of the User using the ID of the mentor like this:

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

Author Comment

by:jkmlgn
Comment Utility
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
 

Author Comment

by:jkmlgn
Comment Utility
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.
0
 
LVL 8

Expert Comment

by:Barry62
Comment Utility
OK, if you figure it out yourself can you give me an assist for my trouble?  Thanks!
0
 

Author Comment

by:jkmlgn
Comment Utility
Absolutely!
0
 

Accepted Solution

by:
jkmlgn earned 0 total points
Comment Utility
Here are the modified Model(database table) Classes.
Mentorship.pdf
0
 
LVL 8

Expert Comment

by:Barry62
Comment Utility
Glad I led you in the right direction.  Thanks.
0
 

Author Closing Comment

by:jkmlgn
Comment Utility
Thanks for your time and assistance Barry62, reviewing our conversation led me to make the changes in the model that allowed for the displaying of the name and not just the Id.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now