部分视图上的表单值

时间:2014-08-25 11:55:41

标签: asp.net-mvc pagination form-post

我想在部分视图上使用mvc分页将值发布到数据库,我想在用户点击下一页时发布上一页的值

  public ActionResult TestPaging(int TestId, int Page = 1)
    {
        var model = PrepareTestModel(TestId);
        ViewBag.TestId = TestId;
        return PartialView("_studentPartial",model.OrderByDescending(v => v.Question_Id).ToPagedList(Page, 1));
}
  private List<Question> PrepareTestModel(int TestId)
        {
             List<Question> model = new List<Question>();
             EAssessmentNew.BAL.StudentBal studBal = new EAssessmentNew.BAL.StudentBal();
             EAssessmentNew.Dal.Student_Answer_Master _studAnsdal = new EAssessmentNew.Dal.Student_Answer_Master();
            model = new Test_Planning().Fetch_Question_By_Test(TestId);

            ViewBag.total = model.Count();

        return model;
        }

@model IPagedList<EAssessmentNew.Models.Question>
@using PagedList
@using PagedList.Mvc
@using (Html.BeginForm("TestStarted", "Student", FormMethod.Post))
{

    //<span>@Html.DropDownListFor(model => Model[0].Question_Id,abc, "Select Course", new { id = "ddlCourse", @class = "dropDown", style = "margin-left:17px;"})</span>



        if (Model != null && Model.Count > 0)
        {
           <input type="hidden" value="@Model[0].TestId" name="TestId"/>
            for (int i = 0; i < Model.Count; i++)
            {
            <div>
                @Html.HiddenFor(m => Model[i].TestId)
                @Html.HiddenFor(m => Model[i].QuestionId)
                 @Html.HiddenFor(m => Model[i].QuestionTypeId)
                <span class="ResLabels">@Model[i].QuestionName</span>


                @if (Model[i].QuestionTypeId == 1)
                {
                    <div>
                        <br />
                        @for (int j = 0; j < Model[i].Options.Count(); j++)
                        {

                            <div>                  

                                     @Html.RadioButtonFor(m => Model[i].SelectedOption, Model[i].Options[j].OptionId)

                                <span class="Options">@Model[i].Options[j].OptionName</span>

                            </div>
                             <br />
                        }

                    </div>
                }
                else
                {

                    <div>
                         <br />
                        @for (int j = 0; j < Model[i].Options.Count(); j++)
                        {

                              <div>     

                                      @Html.CheckBoxFor(m => Model[i].Options[j].IsChecked, new { id = "selectedOption" + (j + 1) })
                                      @Html.HiddenFor(m => Model[i].Options[j].OptionId)




                                 <span class="Options">@Model[i].Options[j].OptionName</span>

                      </div>
                             <br />
                        }
                    </div>
                }
            </div>
            }
        }


         <input type="hidden" name="submitChk" id="submitCheck" Value="0"/>
         <input type="submit" name="abc" value="@ViewBag.EndTime" onclick="submitClick()"> 

          @*<input type="hidden" name="sameCount" value="@QuesCnt">*@
              <input type="hidden" name="End" value="@ViewBag.EndTime" />





<div class="pagedList">
   @Html.PagedListPager(Model, page => Url.Action("TestPaging", "Student", new { page,TestId = ViewBag.TestId }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions { UpdateTargetId="results",HttpMethod="POST"}))
 </div>

}

我已经编写了分页方法现在如何调用post方法并在特定页面上的数据库中提交我如何在分页上调用post方法

0 个答案:

没有答案