Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 标记帮助器选择元素为空,即使其数据源不是空的_C#_Asp.net Core_Asp.net Core Mvc_Visual Studio 2015_Tag Helpers - Fatal编程技术网

C# 标记帮助器选择元素为空,即使其数据源不是空的

C# 标记帮助器选择元素为空,即使其数据源不是空的,c#,asp.net-core,asp.net-core-mvc,visual-studio-2015,tag-helpers,C#,Asp.net Core,Asp.net Core Mvc,Visual Studio 2015,Tag Helpers,我正在使用ASP.NET核心MVC RC2项目,使用“数据库优先模型”。该数据库是著名的Northwind数据库。除了“选择标记帮助器”(一个HTML下拉列表)之外,一切正常,该列表应该填充ViewBag数据,即使ViewBag数据不是空: CustomersController上的以下操作方法正确显示所有客户的列表: public IActionResult Index() { List<Customers> data = repository.SelectAll();

我正在使用ASP.NET核心MVC RC2项目,使用“数据库优先模型”。该数据库是著名的Northwind数据库。除了“选择标记帮助器”(一个HTML下拉列表)之外,一切正常,该列表应该填充
ViewBag
数据,即使
ViewBag
数据不是空:

CustomersController
上的以下操作方法正确显示所有客户的列表:

public IActionResult Index()
{
    List<Customers> data = repository.SelectAll();
    return View("/views/Northwind/Index.cshtml", data);
}
以下是显示可编辑数据的“视图”,下拉列表为空除外:

@model MVCCoreCR2\u Project.Models.Customers
注意:在调试过程中,当我在
处放置断点并将鼠标悬停在
@ViewBag上时。国家/地区
我可以看到视图包中的国家/地区已填充。

a
不是自动关闭标记。这是必须的

<select asp-for="Country" asp-items="ViewBag.Countries" class="form-control"></select>

A
不是自动关闭标签。这是必须的

<select asp-for="Country" asp-items="ViewBag.Countries" class="form-control"></select>


尝试使用
@Html.DropDownListFor(model=>model.selectedCountry,IEnumerable)ViewBag.Countries,new{@class=“form control”})
下次请使用正确的标记。用于旧版ASP.NET MVC Webstack(MVC 1到5)。对于ASP.NET核心使用,请尝试使用
@Html.DropDownListFor(model=>model.selectedCountry,IEnumerable)ViewBag.Countries,new{@class=“form control”})
下次请使用正确的标记。用于旧版ASP.NET MVC Webstack(MVC 1到5)。对于ASP.NET核心的使用,非常感谢您指出我可能没有发现的错误。非常感谢您指出我可能没有发现的错误。
<select asp-for="Country" asp-items="ViewBag.Countries" class="form-control"></select>