在Action Link MVC上提交表格

时间:2014-08-27 06:01:05

标签: asp.net-mvc-4 partial-views form-submit

下面提到的是我的视图页面及其部分视图我想在我的视图页面的操作链接上提交表单值,即我想调用控制器的post mentod,我已经为表单提交javascript写了但是它不起作用

@model IPagedList<EAssessmentNew.Models.Question>
@using PagedList
@using PagedList.Mvc



<script src="~/Scripts/jquery.js"></script>

<script type="text/javascript">
   function someFunction() {
        alert("ok")
        document.getElementById('page').value = cnt;
        $("#testStartedForm").submit();
        return false;
    }

</script>






@using (Html.BeginForm("TestStarted", "Student", FormMethod.Post, new { id = "testStartedForm" }))
{

    //<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>
        }
    }


}


<div class="pagedList">
       @Html.PagedListPager(Model, page => Url.Action("TestPaging", "Student", new { page, TestId = ViewBag.TestId,Model[0].Question_Id,Model[0].SelectedOption, @onclick = "someFunction("+ page +");" }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions { UpdateTargetId = "results", HttpMethod = "POST" }))
     </div>   

此处PagedListPager是我想要在此特定链接上调用Post方法的操作链接

0 个答案:

没有答案