public class TimeZone { public int Id { get; set; } public string DisplayName{ get; set; } }
In some other class, I:
var gmtList = new SelectList( repository.GetSystemTimeZones(), "Id", "DisplayName");
Note. System.Web.Mvc.SelectList
I do not like to write the name of the property with "Id" and "DisplayName". Later, the property name may change and the compiler will not detect this error. C # how to get property name in string?
UPDATE 1
With the help of Christian Heiter, I can use:
var tz = new TimeZone(); var gmtList = new SelectList( repository.GetSystemTimeZones(), NameOf(() => tz.Id), NameOf(() => tz.TranslatedName));
OR
var gmtList = new SelectList( repository.GetSystemTimeZones(), NameOf(() => new TimeZone().Id), NameOf(() => new TimeZone().TranslatedName));
If someone has another idea, without the need to create a new object. Feel free to share it :) thanks.
asdas source share