在表单提交中将值从外部表单传递到内部表单

时间:2013-09-02 11:44:35

标签: c# jquery asp.net-mvc

我的表格就像

@using (Html.BeginForm("Search", "CourseList", FormMethod.Post, new { enctype = 
"multipart/form-data" }))
{............

@foreach (var course in Model.Courses)
         {
             <tr >
                 <td>@course.Date</td>
                 <td>@course.Name</td>
                 <td style="text-align: center;">@course.Units</td>
                 <td>@course.Description</td>

                @using (Ajax.BeginForm("Upload", "CourseList",new AjaxOptions{HttpMethod = "post",}, new { id = course.Id, enctype = "multipart/form-data" }))
                 {
                     <input type="hidden" name="course"  value="@course.Id"/>
                     <td><input id="fileUpload" type="file" name="file" /><input type="submit" class="add-btn-grid"/> 
                     <div id="divFileNames">
                          <ul>
                              @if (course.Files != null)
                              {
                                  foreach (var name in course.Files)
                                  {
                                      <li><a href="@name.Value">@name.Key</a></li>
                                  }
                              }
                          </ul>
                      </div>
                  </td>
                 }

                 <td><a class="add-btn-grid" href="@Url.Action("Index", "Quiz", new { courseId = course.Id })" >Setup Quiz</a> <a href="@Url.Action("AddCourse", "AddCourse", new { courseId = course.Id })" class="add-btn-grid"  >Edit </a></td>
             </tr>
         }
    ......

     <div class="pagination" id="paginationdiv">
        Page @Html.DropDownListFor(m => m.PageSize, new SelectList(Model.PageSizeList, "Key", "Value", Model.PageSize), new { id = "ddlPageSize", onchange = "this.form.submit();" })&nbsp;&nbsp;
        Records @Html.DropDownListFor(m => m.CurrentPage, new SelectList(Model.PageNo, "key", "Value", Model.CurrentPage), new { id = "ddlPageNo", onchange = "this.form.submit();" })
    </div>
}

我的控制器就像

public ActionResult Upload(string course, HttpPostedFileBase file)
    {
        try
        {
            var model = new CourseListViewModel();
            var courseId = Request["id"];
            return View("Index", model);
        }
        catch (Exception ex)
        {
            _logger.LogError(Log4NetLogger.Category.Exception, "Error in : CourseListController.Upload :" + ex.Message);
            return View("Error");
        }
    }

我需要的是在每个内部表单提交中传递分页下拉值。

我想过使用ajax帖子,但由于文件上传,我改为表单提交。

如何有效地处理这种情况。

0 个答案:

没有答案