Ajax.BeginForm 防止跳转到新页面

时间:2022-04-14 18:11:36

@using (Ajax.BeginForm("ChangeCompanyId", "navigation", new { area = "configs" }, new AjaxOptions() { UpdateTargetId = "NavigationTree", OnSuccess = "InitTreeNode" }))
{
    @Html.DropDownList("CompanyId")
}
<link href="@Url.Content("~/Content/themes/Common/css/jquery.treeview.css")" rel="stylesheet" />
<div style="display: none;">
    @Html.CheckBox("IsBarringChildrens", (bool)ViewBag.IsBarringChildrens)
    <span>不含子导航
    </span>
</div>
<div id="NavigationTree">
    @Html.Action("TreeNode", new { CompanyId = (int)ViewBag.CompanyIdValue })
</div>

要引用下面的。

<script src="@Url.Content("~/Scripts/Common/jquery/jquery.unobtrusive-ajax.min.js")"></script>