System.Collections.Generic.IEnumerable不包含Error的定义

时间:2015-12-02 13:35:07

标签: c# asp.net asp.net-mvc list ienumerable

我需要将列表传递给size_t视图,但会出现此错误:

  

System.Collections.Generic.IEnumerable不包含si_id的定义,也没有扩展方法si_id接受System.Collections.Generic.IEnumerable类型的第一个参数(你是否缺少using指令或程序集引用? )

查看

IEnumerable

控制器

            @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

我无法更改[HttpGet] public ActionResult RegisterStudent() { Models.ModelActions action = new Models.ModelActions(); var model = new acgs_qm.Models.CreateStudent { GradeLevel = action.getGrade(), Guardian = action.getGuardian(), si_id = action.getcode("student_info_tb", "si_id", "1") }; List<CreateStudent> stud = new List<CreateStudent>(); stud.Add(model); return View(stud); } ,因为我正在传递我的帖子的价值

IEnumerable

2 个答案:

答案 0 :(得分:2)

如果您的观点仅用于创建一个学生记录,那么请传入一个学生,而不是一个&#39;只有一行。

将您的@model更改为:

@model acgs_qm.Models.CreateStudent

你的Controller行动:

return View(model); // model is a single student record

答案 1 :(得分:1)

我想要显示列表中必须循环的所有学生,例如

@model IEnumerable<acgs_qm.Models.CreateStudent>    
@foreach (var student in Model) {
        <div class="editor-label">
                @Html.LabelFor(m => student.si_id)
         </div>
         @* etc ... *@
    }
相关问题