我需要一個列表傳遞給IEnumerable
視圖的定義,但這個錯誤出來:System.Collections.Generic.IEnumerable不包含錯誤
System.Collections.Generic.IEnumerable不包含定義和SI_ID沒有擴展方法SI_ID接受型System.Collections.Generic.IEnumerable的第一個參數可以找到(是否缺少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
控制器
[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);
}
我不能,因爲我通過我的文章的價值這樣
[HttpPost]
public ActionResult RegisterStudent(CreateStudent Create, string submitbutton, string searchTerm)
{
acgs_qm.Models.ModelActions Ma = new acgs_qm.Models.ModelActions();
List<CreateStudent> stud = new List<CreateStudent>();
switch (submitbutton)
{
case "search":
stud = Ma.searchStud(searchTerm);
return View(stud);
如果你做模型[0] .si_id會發生什麼? – VictorySaber
你假裝它是一個單一的項目,但實際上它是一個列表。 –
@PatrickHofman我該如何解決這個問題? – Renz