Currently, I have 2 lists that bind data from a database on my view ... I used a custom Viewmodel model and not very typed. Here is 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 these two lists using the two buttons (β) 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 list and save it in another? And after this change must be recorded in the database. Therefore, UPDATE the database. Can I use modelstate to update values ββin a database?
I am not very good at asp.net mvc, so I hope you understand me ...
Thanks in advance!
Lorenzo
source share