t4mvc - getting the value of a dropdownlist into the ActionResult parameters in Ajax.BeginForm

303 views Asked by At

I must be missing something, but...

Say I have the following Ajax form:

using (Ajax.BeginForm(MVC.Admin.TutorEditor.AddTutorCourse(Model.TutorName, TutorRoleId, CourseId),
                        new AjaxOptions
                        {
                            UpdateTargetId = "TutorCourses",
                            OnBegin = "isValidPleaseWait",
                            LoadingElementId = "PleaseWait"
                        },
                        new { name = "AddTutorCourseForm", id = "AddTutorCourseForm" }))
        {    

        <fieldset>
            <legend>Add Course</legend>
            <div class="editor-label">
                @Html.LabelFor(model => model.AllCourses)
                @Html.DropDownList("CourseId", Model.AllCourses, "-- Choose Course --", new { style = "width:180px;" })
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.TutorRoles)
                @Html.DropDownList("TutorRoleId", Model.TutorRoles, "-- Choose Role --", new { style = "width:180px;" })
            </div>
            <input type="submit" value="Add Course" />
        </fieldset>
        }
    }

I want to use it to call an Action (AddTutorCourse) that has 3 params:

  1. string TutorName: No problem here, I can get this from the model: Model.TutorName

  2. I want the value of the "TutorRoleId" dropdownlist

  3. I want the value of the "CourseId dropdownlist.

Ie, calliing AddTutorCourse should look like:

        [HttpPost]
        public virtual ActionResult AddTutorCourse(string username, int TutorRoleId, int CourseId)
        {
            // do whatever...
            return View(service.ViewModel);
        }

The Question is:

At runtime, how to get the values into the following bit of code (note ??):

MVC.Admin.TutorEditor.AddTutorCourse(Model.TutorName, ??, ??)

1

There are 1 answers

0
Darin Dimitrov On BEST ANSWER

Have you tried:

MVC.Admin.TutorEditor.AddTutorCourse(Model.TutorName, 0, 0)