【问题标题】:Error "An item with the same key has already been added" in asp.net MVC在 asp.net MVC 中出现错误“已添加具有相同密钥的项目”
【发布时间】:2021-08-06 09:52:16
【问题描述】:

我添加了带有一些静态值的 drop,但它显示错误

@Html.DropDownListFor(model => model.MRStype, new SelectList(new List { 新{值=“0”,文本=“--选择--”},enter code here 新 {Value = "1", Text = "Internal Issue" }, 新 { 值 = “2” ,文本 = “外部问题” } }, “价值”, “文本” ), new { @class= "form-control", @id = "ddlSourceType" })

【问题讨论】:

    标签: asp.net model-view-controller


    【解决方案1】:

    将您的代码更改为这个(使用列表而不是列表)

    @Html.DropDownListFor(model => model.GlobalStudentId, new SelectList(new List<object> { new { Value = "0", Text = "--Select--" }, new { Value = "1", Text = "Internal Issue" }, new { Value = "2", Text = "External Issue" } }, "value", "text"), new { @class = "form-control", @id = "ddlSourceType" })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-02
      • 1970-01-01
      • 1970-01-01
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多