Currently I have 2 listboxes binding data from a database on my view... I've used a custom Viewmodel and it is not strongly-typed. Here's the code:
<%@ 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>
Well, now I want to move items between those two listboxes using two buttons (>>) and (<<) And when the user clicks the apply button, the changes must be recorded in the database.
StudentModel:
namespace ProjectenII.Models.Domain
{
public class StudentModel
{
public IEnumerable<SelectListItem> NormalStudentsList { get; set; }
public IEnumerable<SelectListItem> StudentsNoClassList { get; set; }
}
}
Controller:
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);
}
So how can I get the selected value of one listbox and save it to the other one? And afterwards, the changes must be written down in the database. So UPDATE the database. Can I make use of modelstate to update the values in the database?
I'm not very good at asp.net mvc, so I hope you understood me...
Thanks in advance!!