为了账号安全,请及时绑定邮箱和手机立即绑定

在ASP.NETCoreMVC中选择Tag Helper

在ASP.NETCoreMVC中选择Tag Helper

C#
德玛西亚99 2019-07-01 20:33:01
在ASP.NETCoreMVC中选择Tag Helper在ASP.NETCore中的SELECT标记助手方面,我需要一些帮助。我有一个员工列表,我正试图绑定到一个选择标记助手。我的员工List<Employee> EmployeesList所选择的值将进入EmployeeId财产。我的视图模型如下所示: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条经验 获得超7个赞

您也可以使用IHtmlHelper.GetEnumSelectList。

    // 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;


查看完整回答
反对 回复 2019-07-01
  • 3 回答
  • 0 关注
  • 964 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信