0

我有以下主要观点:-

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

@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 元素?

谢谢

4

2 回答 2

1

不要设置 UpdateTargetId 并更改您的 onsuccess 方法(deletionconfirmation),如下所示

deletionconfirmation = function(data)
{
    $(data).prependTo("#tableBody > tbody");
//some other code.
}
于 2013-12-30T20:33:02.270 回答
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

于 2013-11-05T22:09:07.900 回答