目前,我有2个列表框在我的视图中绑定数据库中的数据......我使用了自定义Viewmodel,并且它不是强类型的。 下面的代码:ASP.NET mvc:在两个列表框之间移动项目
<%@ 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>
<div class="editor-field">
<%: Html.ListBox("IndexStudentsNormal", Model.NormalStudentsList)%>
</div>
<input type="submit" name="add"
id="add" value=">>" />
<br />
<input type="submit" name="remove"
id="remove" value="<<" />
<div class="editor-field">
<%: Html.ListBox("IndexStudentsNoClass", Model.StudentsNoClassList)%>
</div>
<input type="submit" name="apply" id="apply" value="Save!" />
</asp:Content>
好了,现在我想用两个按钮(>>)和(< <),当用户点击应用按钮,必须记录的更改这两个列表框之间项在数据库中。
StudentModel:
namespace ProjectenII.Models.Domain
{
public class StudentModel
{
public IEnumerable<SelectListItem> NormalStudentsList { get; set; }
public IEnumerable<SelectListItem> StudentsNoClassList { get; set; }
}
}
控制器:
public ActionResult IndexStudents(Docent docent, int id, int klasgroepid)
{
var studentModel = new StudentModel
{
NormalStudentsList = docent.GeefStudentenNormaalList(id, klasgroepid),
StudentsNoClassList = docent.GeefStudentenNoClassList(id, klasgroepid)
};
return View(studentModel);
}
所以,我怎么能得到一个列表框的设定值,并将其保存到另一个? 然后,更改必须记录在数据库中。 因此更新数据库。 我可以使用modelstate更新数据库中的值吗?
我不是在asp.net mvc的非常好,所以我希望你明白我的意思...提前
谢谢!
试试这个https://www.codeproject.com/script/Membership/LogOn.aspx?rp=http%3a%2f%2fwww.codeproject.com %2fArticles%2f136730%2fASP-NET-MVC-Basics-Working-with-ListBoxes&download = true –