I have a model that looks kinda like this:
public class Notes
{
public int NoteID {get; set;}
public string Note {get; set;}
public int CustomerID {get; set;}
{
On the Notes Details view, I would like to be able to show Customer Name instead of CustomerID. Obviously if this were a Create or Edit view I use a dropdown list. However I am not sure how to show the value and not the ID in a read only Details view.
Thanks!
Code First is mainly... code, not Database logic.
So, instead of having the Foreign Keys (like CustomerID) in your models (it's also possible, and sometimes needed, but not always), you'll be more confortable having a reference property
public virtual Customer Customer {get;set;}
So in your view having Notes as Model, you could simply use
@Html.DisplayFor(m => m.Customer.Name);
When you retrieve your Notes entity, don't forget to include the related entities / properties needed for your View / ViewModel (I let you read about lazy loading)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With