在ASP.NETCoreMVC中選擇Tag Helper在ASP.NETCore中的SELECT標記助手方面,我需要一些幫助。我有一個員工列表,我正試圖綁定到一個選擇標記助手。我的員工List<Employee> EmployeesList所選擇的值將進入EmployeeId財產(chǎn)。我的視圖模型如下所示:public class MyViewModel
{
public int EmployeeId { get; set; }
public string Comments { get; set; }
public List<Employee> EmployeesList {get; set; }
}我的雇員班如下所示:public class Employee
{
public int Id { get; set; }
public string FullName { get; set; }
}我的問題是如何告訴選擇標記助手使用Id作為顯示時的值FullName在下拉列表里?<select asp-for="EmployeeId" asp-items="???" />我希望能幫上忙。謝謝。
3 回答

aluckdog
TA貢獻1847條經(jīng)驗 獲得超7個贊
// Summary: // Returns a select list for the given TEnum. // // Type parameters: // TEnum: // Type to generate a select list for. // // Returns: // An System.Collections.Generic.IEnumerable`1 containing the select list for the // given TEnum. // // Exceptions: // T:System.ArgumentException: // Thrown if TEnum is not an System.Enum or if it has a System.FlagsAttribute. IEnumerable<SelectListItem> GetEnumSelectList<TEnum>() where TEnum : struct;
- 3 回答
- 0 關(guān)注
- 986 瀏覽
添加回答
舉報
0/150
提交
取消