6

There is a view displaying 5 dropdown lists populated with all available courses from relevant 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>

Student will select one course from each dropdown lists and press Register button.

My question is how I will get selected courses in relevant controller?

Thanks.

3
  • can you please tell me why you have Bind with the same value m.Course.CId in each dropdown? Commented Jul 29, 2013 at 12:07
  • Because I need to show all courses in each dropdown list... Commented Jul 29, 2013 at 12:15
  • Yes, But have binded the same value for each dropdown. I suppose it should not be the case Commented Jul 29, 2013 at 12:20

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I introduced 5 course variables in CourseRegisterModel class and get their values on POST request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.