【发布时间】:2021-10-22 13:28:43
【问题描述】:
我有一个用于在 razor 页面中创建页面以填写组织详细信息的表单。 该组织有一个字段 ParentId(它可能属于另一个组织)。 我想在 Select 中迭代 parentIds 列表(并在选项中显示标题)。 我收到此错误:以下示例生成 CS1579,因为 MyCollection 类不包含公共 GetEnumerator 方法:
//Model
public class Organisation : EntityBase
{
[Key]
public int Id { get; set; }
public Organisation Parent { get; set; }
[Required]
public string Title { get; set; }
}
//Controller
public IActionResult Create()
{
IEnumerable<Organisation> objList = _db.Organisations;
return View(objList);
}
//View
@model MindNavigatorDB.Entities.Organisation;
<form asp-action="Create" method="post">
<div class="form-group">
<label asp-for="Parent" class="control-label"></label>
<select id="country"
class="form-select form-control"
asp-for="Parent"
aria-label="Select">
@foreach (Organisation item in Model)
{
<option selected="selected" value="">Please select</option>
}
</select>
<span asp-validation-for="Parent" class="text-danger"></span>
</div>
</form>
【问题讨论】:
-
发布的代码似乎不包含名为 MyCollection 的类
标签: c# .net asp.net-core razor razor-pages