Ajax.BeginForm第一次工作,但从第二次调用调用方法两次

时间:2016-04-21 10:41:35

标签: asp.net-mvc ajax.beginform

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

我的选择部分视图

<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);    
}

表单首次正确发布,但从第二次开始,它会调用操作方法tiwce中的所有代码行,有时会以偶然的顺序调用,最后填充网格,或者不发送任何结果。

1 个答案:

答案 0 :(得分:0)

解决了..我的updatetargetid div不是父div .. 取而代之..