本文介绍了Ajax.BeginForm第一次工作,但是从第二次调用开始两次调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ajax.BeginForm 第一次工作,但是从第二次调用开始两次调用方法。.我已经引用了所有必需的脚本。
首先,在我的主视图中,我有一个用于两个partail视图的公共div,并基于单选按钮选择加载各个视图。

Ajax.BeginForm works first time, but calls method twice from second call.. I have referenced all the required scripts.Firstly, In my main view, I have a common div for two partail views and I am loading respective views based on a radio button selection.

我的选择局部视图

<div>
@using (Ajax.BeginForm("GetRandomThirdPartyList", "RandomList", new AjaxOptions { UpdateTargetId = "Contractors" }, new { id = "FORM" }))
{
    <div id="Contractors">
        <div id="ThirdParty">
            <br />
            <h3>Third Party Contractors</h3><hr />
            <div>Enter High Risk Percentage: @(Html.Kendo().TextBoxFor<int?>(model => model.HighThirdPercent)
            .HtmlAttributes(new { style = "width: 50px; height:25px" })
            )
            </div>

            <input type="submit" value="Generate Report" class="k-button btn-primary" id="btn_thirdpaty" />

            @*&nbsp;&nbsp;<b>@Html.DisplayFor(model => model.TotHighRisk) HighRisk Employees / @(Html.DisplayFor(model => model.TotLowRisk)) LowRisk Employees</b>*@
        </div>
        <br />

        <div id="ThirdPartytab">
            <div id="ReportForm" class="k-content">
                <ul id="tabstrip2" class="nav nav-tabs" role="tablist">
                    <li class="active"><a href="#ThirdParty" role="tab" data-toggle="tab">HighRisk Third Party Contractors</a></li>
                    @* <li style="float:right"><a href="#"><img src="~/Images/icon_ssrs.png" title="Export to SSRS" /></a></li>*@
                </ul>
                @*Tab Content Containers*@
                <div class="tab-content">
                    @if (Model.ThirdParty != null)
                    {

                        <div class="tab-pane fade in active" id="ThirdPartytab"> @Html.Partial("ThirdParty", Model) </div>
                    }
                </div>
            </div>
        </div>
    </div>
}

我的控制器:

int tphigh = 0;

// GET: /RandomList/
[HttpPost]
public ActionResult GetRandomThirdPartyList(VM.RandomList random)
{
    // tphigh=Convert.ToInt32(random.HighThirdPercent);
    if (random.HighThirdPercent != null)
    {
        tphigh = Convert.ToInt32(random.HighThirdPercent);
        // RedirectToAction("HighRiskCOPL", high);
    }
    List<VM.RiskList> risklist = (List<VM.RiskList>)AutoMapDomainModel<List<VM.RiskList>>(randomDBentity.GetRandomList(0, 0, tphigh,null));
    mainlist.HighThirdPercent = tphigh;
    mainlist.ThirdParty = //some list as third party is a Ienumerable
    return PartialView("ThirdPartyContractors",mainlist);
}

表单第一次正确发布,但是从第二次开始,它调用所有操作方法中的代码行有时会随意排列,最后要么填充网格,要么不发送任何结果。

The form posts properly first time, but from second time, it calls all the code lines in the action method tiwce, sometimes in a haphazard order and finally either populates the grid, or doesnt send any result.

推荐答案

解决。.我的updatetargetid div不是父div。.
代替了它。.

Solved it.. My updatetargetid div was not the parent div..replaced that..

这篇关于Ajax.BeginForm第一次工作,但是从第二次调用开始两次调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 00:27