【问题标题】:MVC6 Taghelper Select Control with Selected Item in indexed modelMVC6 Tag Helper Select Control with Selected Item in index model
【发布时间】:2015-11-27 10:10:58
【问题描述】:

我正在尝试根据索引情况下的模型设置选择控件的选定值。我有以下代码 -

<select asp-for="Items.Details[i].One"
    asp-items="Utility.DropdownListItems(date, Model.Items.Details[i].One)">
</select>

我在返回 SelectList 的实用程序中设置所选项目,并希望设置下拉列表的所选项目,但这不起作用。如果我检查选项元素,则没有选定的标签。 我知道在 Mvc HtmlHelpers 的先前迭代中存在索引数据问题。有谁知道这在 MVC6 中是否已解决?

【问题讨论】:

  • 请参阅在 MVC 6 中将选项组与 Select TagHelper 一起使用 ow.ly/Sa392

标签: asp.net-core-mvc tag-helpers


【解决方案1】:

对于 HTML 和标签助手,生成的 &lt;option&gt; 元素是根据表达式值(在您的情况下为 Item.Details[i].One)选择的。选择列表中的IsSelected 仅在表达式值为null 时才重要,即在创建案例中。

我们已更正了与 MVC 6 中的索引数据相关的一些问题。如果仍有问题,请在 https://github.com/aspnet/Mvc/issues 提出问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    • 1970-01-01
    相关资源
    最近更新 更多