How can I choose which property is displayed in Html.DropDownListFor for a some type?
For example I have the following class from which I want to select values
public partial class Artysta
{
public Artysci()
{
this.SpektaklArtysta = new HashSet<SpektaklArtysta>();
}
[Key]
public int ArtystaID { get; set; }
public string Imie { get; set; }
public string Nazwisko { get; set; }
}
Here is a generated code for edit View which sometimes displays Imie and from time to time Nazwisko.
@using (Html.BeginForm())
{
@model Teatr.Models.SpektaklArtysta
<div class="form-group">
@Html.LabelFor(model => model.ArtystaID, "Artysta", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ArtystaID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ArtystaID, "", new { @class = "text-danger" })
</div>
</div>
}
I would like to set displayed property to Nazwisko, how can I achieve that?
UPDATE:
Here is actual model that this View was generated.
public partial class SpektaklArtysta
{
public int SpektaklID { get; set; }
public int ArtystaID { get; set; }
public int RolaArtystyID { get; set; }
[Key]
public int SpektaklArtystaID { get; set; }
public virtual Artysci Artysci { get; set; }
public virtual RolaArtysty RolaArtysty { get; set; }
public virtual Spektakle Spektakle { get; set; }
}