Reputation: 3022
i have two entities page and user.
the page has a property userId
on the create of page i have this code
ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName");
but i want to show to the user the FirstName + " " + LastName i tried to add a FullName property to the User model
public virtual string FullName()
{
return FirstName + " " + LastName;
}
and change the code to
ViewBag.UserId = new SelectList(db.Users, "Id", "FullName");
but then i get an error
'System.Data.Entity.DynamicProxies.User_EA60FEF07DE73591E6CDB805AD4C97662C5746A392A085CE7E70AA1B78B0DD78' does not contain a property with the name 'FullName'.
Upvotes: 1
Views: 665
Reputation: 20031
Your full name is a method and not a property.
Try
public virtual string FullName {
get { return FirstName + " " + LastName; }
}
Upvotes: 3