在我看来,我遇到了当前错误:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ProjectenII.Models.Domain.StudentModel>"%>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
IndexStudents
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>IndexStudents</h2>
<%using (Html.BeginForm()) { %>
<%=Html.ListBoxFor(model => model.NormalSelected, new MultiSelectList(Model.NormalStudentsList, "StudentNummer", "Naam", Model.NormalSelected), new { size = "6" }); %>
<input type="submit" name="add"
id="add" value=">>" /><br />
<input type="submit" name="remove"
id="remove" value="<<" />
<%=Html.ListBoxFor(model => model.NoClassSelected, new MultiSelectList(Model.StudentsNoClassList, "StudentNummer", "Naam", Model.NoClassSelected)); %>
<% } %>
<%=Html.HiddenFor(model => model.Save) %>
<input type="submit" name="apply" id="apply" value="Save!" />
</asp:Content>
它在 listboxfor() 方法中给了我一个错误......说“)预期”。
但我关闭了所有的开始标签......虽然很奇怪!我想用它做什么:我想将项目从一个列表框移动到另一个,然后更新数据库。所以我想用formCollection来做,除非有其他方法?
学生有一个名为“classID”的字段,当我更新数据库时,该值需要从当前值更改为“0”。我认为最好的方法是使用 formCollections?不是吗?这是我的学生模型
public class StudentModel
{
public IEnumerable<Student> NormalStudentsList { get; set; }
public IEnumerable<Student> StudentsNoClassList { get; set; }
public string[] NormalSelected { get; set; }
public string[] NoClassSelected { get; set; }
public string Save { get; set; }
}
控制器:
public ActionResult IndexStudents(Docent docent, int id, int klasgroepid)
{
var studentModel = new StudentModel
{
NormalStudentsList = docent.GeefStudenten(id, klasgroepid),
StudentsNoClassList = docent.GeefStudenten(id, klasgroepid)
};
return View(studentModel);
}
我有两个问题:如何修复错误?以及如何更新数据库?
我建议使用“UpdateModel()”...?
提前致谢!!