C# System.Collections.Generic.IEnumerable不包含错误的定义
我需要将列表传递给C# System.Collections.Generic.IEnumerable不包含错误的定义,c#,asp.net,asp.net-mvc,list,ienumerable,C#,Asp.net,Asp.net Mvc,List,Ienumerable,我需要将列表传递给IEnumerable视图,但出现以下错误: System.Collections.Generic.IEnumerable不包含si_id的定义,并且找不到接受System.Collections.Generic.IEnumerable类型的第一个参数的扩展方法si_id(是否缺少using指令或程序集引用?) 查看 @model IEnumerable<acgs_qm.Models.CreateStudent> &
IEnumerable
视图,但出现以下错误:
System.Collections.Generic.IEnumerable不包含si_id的定义,并且找不到接受System.Collections.Generic.IEnumerable类型的第一个参数的扩展方法si_id(是否缺少using指令或程序集引用?)
查看
@model IEnumerable<acgs_qm.Models.CreateStudent>
<div class="editor-label">
@Html.LabelFor(model => model.si_id) //Error
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.si_id, new { @readonly = "readonly" })
@Html.ValidationMessageFor(model => model.si_id)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.si_fname)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.si_fname)
@Html.ValidationMessageFor(model => model.si_fname)
</div>
//etc
如果您的视图只打算创建一个学生记录,那么请传入一个学生,而不是仅包含一行的“列表” 将您的
@model
更改为:
@model acgs_qm.Models.CreateStudent
以及控制器的操作:
return View(model); // model is a single student record
如果您的视图只打算创建一个学生记录,那么请传入一个学生,而不是仅包含一行的“列表” 将您的
@model
更改为:
@model acgs_qm.Models.CreateStudent
以及控制器的操作:
return View(model); // model is a single student record
如果你想显示列表中的所有学生,你必须在上面循环,例如
@model IEnumerable<acgs_qm.Models.CreateStudent>
@foreach (var student in Model) {
<div class="editor-label">
@Html.LabelFor(m => student.si_id)
</div>
@* etc ... *@
}
@model IEnumerable
@foreach(模型中的var学生){
@LabelFor(m=>student.si_id)
@*等等*@
}
如果要显示列表中的所有学生,则必须循环显示,例如
@model IEnumerable<acgs_qm.Models.CreateStudent>
@foreach (var student in Model) {
<div class="editor-label">
@Html.LabelFor(m => student.si_id)
</div>
@* etc ... *@
}
@model IEnumerable
@foreach(模型中的var学生){
@LabelFor(m=>student.si_id)
@*等等*@
}
如果你做了模型[0]。你知道会发生什么?你假装它是一个项目,但实际上它是一个列表。@PatrickHofman我如何解决这个问题,先生?你正在创建一个列表,并且只向其中添加1个CreateStudent
-为什么不直接将CreateStudent
设置为模型-返回视图(模型)
然后@model acgs\u qm.Models.CreateStudent
。如果您使用模型[0],这将解决错误。si_id发生了什么?您假装它是一个项目,但实际上它是一个列表。@PatrickHofman我如何解决这个问题,先生?您正在创建一个列表
,并且只向其中添加1个CreateStudent
-为什么不将CreateStudent
设置为模型-返回视图(模型)
然后@model acgs\u qm.Models.CreateStudent
。这将解决错误