Ajax.BeginForm works first time, but calls method twice from second call

不打扰是莪最后的温柔 提交于 2019-12-25 06:59:01

问题


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.

My Select Partial View

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

My Controller :

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.


回答1:


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



来源:https://stackoverflow.com/questions/36767141/ajax-beginform-works-first-time-but-calls-method-twice-from-second-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!