gpt4 book ai didi

java - 如何使用 Ajax.beginform + 部分 View 更新我的表,在 ym asp.net mvc Web 应用程序内部

转载 作者:行者123 更新时间:2023-12-02 06:34:25 24 4
gpt4 key购买 nike

我有以下主要观点:-

@using (Ajax.BeginForm("AssignCustomer", "Firewall", new AjaxOptions

{
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = ??????????,
LoadingElementId = "progress",
HttpMethod= "POST",
OnSuccess="submitform"
}))
{
@Html.ValidationSummary(true)
@Html.AntiForgeryToken()
@Html.HiddenFor(model=>model.FirewallCustomer.ID)


<div>
<span class="f">Customer Name</span>


@Html.TextBoxFor(model => model.FirewallCustomer.CustomerName, new { data_autocomplete_source = Url.Action("CustomerAutoComplete", "Firewall") })

@Html.ValidationMessageFor(model => model.FirewallCustomer.CustomerName)




</div>


<input type="submit" value="Save" class="btn btn-primary"/>
}
<p><img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress" /></p>
<table id ="myTable" class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th class="f"> Customer Name </th>
<th></th>

</tr></thead>
<tbody id="tableBody">

@foreach(var info in Model.Firewall.FirewallCustomers.OrderBy(a=>a.CustomerName)){

<tr id= "@info.CustomerName.Replace(" ", string.Empty)">


<td> @Html.ActionLink(info.CustomerName, "Index", "Customer", new {searchTerm=info.CustomerName},null)</td>
<td> @Ajax.ActionLink("Delete",
"DeleteCustomerFirewall", "Firewall",
new { firewallid = info.ID, customername = info.CustomerName},

new AjaxOptions
{ Confirm = "Are You sure You want to delete " + info.CustomerName,
HttpMethod = "Post",

OnSuccess = "deletionconfirmation",
OnFailure = "deletionerror"
})</td>
</tr>
}
</tbody>

当单击 ajax.beginform 时,我需要插入以下部分 View 作为表格的第一行:-

@model TMS.Models.FirewallCustomer

<tr id= "@Model.CustomerName.Replace(" ", string.Empty)">


<td> @Html.ActionLink(Model.CustomerName, "Index", "Customer", new {searchTerm=Model.CustomerName},null)</td>
<td> @Ajax.ActionLink("Delete",
"DeleteCustomerFirewall", "Firewall",
new { firewallid = Model.ID, customername = Model.CustomerName},

new AjaxOptions
{ Confirm = "Are You sure You want to delete " + Model.CustomerName,
HttpMethod = "Post",

OnSuccess = "deletionconfirmation",
OnFailure = "deletionerror"
})</td>
</tr>

任何人都可以建议我应该在 Ajax.BeginForm 的 UpdateTargerID 中添加什么内容吗?这个 id 应该是表 ID (id="myTable") 还是 Tbody ID (id= "tableBody") 还是另一个 DOM 元素?

谢谢

最佳答案

我认为 Ajax.BeginForm 不可能做到这一点。我的建议是使用 jquery 的 $.ajax$.post然后在成功处理程序上,将数据添加到您的 tbody

$.post("/FireWall/AssignCustomer", $("#formId").serialize(),
function (data) {
$(data).prependTo("table > tbody");
});

编辑:

未测试:使用Ajax.BeginForm尝试添加一个空的第一行 <tr id="firstRow"></tr>在你的表中然后将其用作 targetIdInsertionMode.InsertAfter

关于java - 如何使用 Ajax.beginform + 部分 View 更新我的表,在 ym asp.net mvc Web 应用程序内部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19799800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com