有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用Ajax用新行更新我的表。beginform+局部视图,位于ym asp内部。net mvc web应用程序

我的主要观点如下:-

@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时。我需要插入以下局部视图作为表的第一行:-

@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的UpdateTargetId中添加什么。Beginfound;这个id应该是表id(id=“myTable”)还是Tbody id(id=“tableBody”)或其他DOM元素

谢谢


共 (1) 个答案

  1. # 1 楼答案

    我认为这在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