开发者

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

开发者 https://www.devze.com 2023-02-08 01:59 出处:网络
I must be missing something, but... Say I have the following Ajax form: using (Ajax.BeginForm(MVC.Admin.TutorEditor.AddTutorCourse(Model.TutorName, TutorRoleId, CourseId),

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, ??, ??)


Have you tried:

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

精彩评论

暂无评论...
验证码 换一张
取 消