Get selected values ​​from multiple selectlists in MVC3 controller

There is a view displaying 5 drop-down lists filled with all available courses from the corresponding table:

@model StudentRegistrationPortal.Models.CourseRegisterModel @{ ViewBag.Title = "registerCourses"; } <h2>Welcome @Context.User.Identity.Name </h2> @Html.ActionLink("[Sign Out]", "SignOut", "Admin") @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>Following are available Courses - Please select Courses to Register</legend> <table> <tr> <td> <div class="editor-label"> Course-1: </div> </td> <td> <div class="editor-field"> @Html.DropDownListFor(m => m.Course.CId, Model.CoursesList) </div> </td> </tr> <tr> <td> <div class="editor-label"> Course-2: </div> </td> <td> <div class="editor-field"> @Html.DropDownListFor(m => m.Course.CId, Model.CoursesList) </div> </td> </tr> <tr> <td> <div class="editor-label"> Course-3: </div> </td> <td> <div class="editor-field"> @Html.DropDownListFor(m => m.Course.CId, Model.CoursesList) </div> </td> </tr> <tr> <td> <div class="editor-label"> Course-4: </div> </td> <td> <div class="editor-field"> @Html.DropDownListFor(m => m.Course.CId, Model.CoursesList) </div> </td> </tr> <tr> <td> <div class="editor-label"> Course-5: </div> </td> <td> <div class="editor-field"> @Html.DropDownListFor(m => m.Course.CId, Model.CoursesList) </div> </td> </tr> </table> <p> <input type="submit" value="Register" /> </p> </fieldset> } <div> @Html.ActionLink("Back to List", "Home","Student") </div> 

The student will select one course from each drop-down list and click the "Register" button.

My question is, how do I get the selected courses in the appropriate controller?

Thanks.

+6
source share
1 answer

What you really have to do is your model has the properties SelectedCourse1, SelectedCourse2, etc., fill them accordingly and send the model back to the controller

+3
source

Source: https://habr.com/ru/post/950526/


All Articles