jQuery技术:使用jquery ajax post将行附加到表

我正在尝试在我的asp.net MVC 5应用程序中动态地将行附加到表中。 这是表:

 @foreach (var item in Model.AcquisitionCosts) { @Html.Partial("CostViewModel", item); } 
Description Quantity Rate ($) Amount ($) Delete

单击添加行按钮时,它将调用jquery ajax函数。 这使得调用控制器返回局部视图。

返回的局部视图如下所示:

         

但是,在我附加到表后。 从html中删除

and

标记,仅附加输入标记。

 $("#addstrategy").click(function () { $.ajax({ type: "post", url: "/Wizard/StrategyRow", cache: false, datatype: "html", success: function (html) { alert(html); $("#acquisition-cost tbody").append(html); } }); }); 

响应警报,所有标签都在那里,他的html正确形成。

控制器事件:

[HttpPost] public PartialViewResult StrategyRow(){return PartialView(“CostViewModel”,new AcquisitionCostViewModel()); }

部分视图:

 @using (Html.BeginCollectionItem("costrow")) {  @Html.TextBoxFor(model => model.Description, new { maxlength = "50", @class = "form-control text-left" }) @Html.TextBoxFor(model => model.Quantity, new { maxlength = "15", @class = "form-control text-center auto", @placeholder = "0", @data_v_max = "9999999999999", @data_v_min = "0" }) @Html.TextBoxFor(model => model.Rate, new { maxlength = "15", @class = "form-control text-right auto", @placeholder = "0" }) @Html.TextBoxFor(model => model.Amount, new { maxlength = "15", @class = "form-control text-right auto", @placeholder = "0" })   } 

我已经多次查看了代码,但我可以找到为什么

and

被.append()函数删除了。

谢谢Captain0。

将我的部分视图更改为:

  @using (Html.BeginCollectionItem("costrow")) { @Html.TextBoxFor(model => model.Description, new { maxlength = "50", @class = "form-control text-left" }) @Html.TextBoxFor(model => model.Quantity, new { maxlength = "15", @class = "form-control text-center auto", @placeholder = "0", @data_v_max = "9999999999999", @data_v_min = "0" }) @Html.TextBoxFor(model => model.Rate, new { maxlength = "15", @class = "form-control text-right auto", @placeholder = "0" }) @Html.TextBoxFor(model => model.Amount, new { maxlength = "15", @class = "form-control text-right auto", @placeholder = "0" })  }  

修复了这个问题。 现在输入标签现在位于

标签内。

    在响应中,尝试将

    标记之前的输入移动到第一个td。 见下文。

    我使用你提供的响应尝试了它并且无法正确呈现,但是当我删除初始输入时它工作正常。

    需要了解更多jQuery教程分享使用jquery ajax post将行附加到表,都可以关注jQuery技术分享栏目—计算机技术网(www.ctvol.com)!

               

      以上就是jQuery教程分享使用jquery ajax post将行附加到表相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/982340.html

      (0)
      上一篇 2021年12月13日
      下一篇 2021年12月13日

      精彩推荐