首页 > 解决方案 > 为什么 jquery datable 显示旧记录而不是新记录?

问题描述

我在页面加载时由视图模型填充数据表。没关系。

现在我想在单击下拉列表时用一条记录填充它。但是数据表显示的是旧记录而不是新记录。

我试过这个:

        table = $("#tblCertificates").DataTable();

        $.get("/CertificatesNew/FillCertificates", data);

        table.clear();

但不工作。我想在重新填充新数据之前使 jquery 数据表为空。

 [HttpGet]
        [OutputCache(NoStore = true, Duration = 0)]
        public ActionResult FillCertificates(int ID)
        {
            InspectionReportsViewModel InspectionReportsViewModel = new InspectionReportsViewModel();

            try
            {

                InspectionReportDAL InspectionReportDAL = new DAL.InspectionReportDAL();
                InspectionReportsViewModel.InspectionReportList = InspectionReportDAL.GetInspectionReportListFilteredByClientID(ID);

                ClientsDAL clientsDAL = new ClientsDAL();

                ViewBag.ClientsList = clientsDAL.GetClientsList();

                return View("Index", InspectionReportsViewModel); 
            }
            catch
            {
                return View();
            }

        }

api调用:

<script type="text/javascript">
        $('#tblCertificates').DataTable({
            responsive: true,
            searching: true,
            ordering: false,

        });

        $("#SearchInspectionReport_Client_ID").change(function () {
            var ID = $("#SearchInspectionReport_Client_ID").val(); //Client ID



            //if(!Number(ID)) // to check if '-Select-' has been selected, so in that case it should be stopped from further execution
            //{
            //    $("#InspectionReport_PoNo").val('');
            //}

            data = { 'ID': ID } //Client ID

            table = $("#tblCertificates").DataTable();
            //oSettings = table.fnSettings();



            $.get("/CertificatesNew/FillCertificates", data);

            table.clear();
        });

    </script>
}

桌子:

<tbody>
                    @foreach (var InspectionReport in this.Model.InspectionReportList)
                    {
                        <tr>

                            <td>@InspectionReport.VelosiProjectNo</td>
                            <td>@InspectionReport.VelosiReportNo</td>
                            <td style="@(@InspectionReport.Status == 0 ? "Background-color: lightblue" : @InspectionReport.Status == 1 ? "Background-color:skyblue" : @InspectionReport.Status == 2 ? "Background-color: lightgray" : @InspectionReport.Status == 3 ? "Background-color: #99CC99" : @InspectionReport.Status == 4 ? "Background-color: #FF3333" : "")">
                                @(@InspectionReport.Status == 0 ? "Prepared" : @InspectionReport.Status == 1 ? "Reviewed" : @InspectionReport.Status == 2 ? "Approved" : @InspectionReport.Status == 3 ? "Issued" : @InspectionReport.Status == 4 ? "Rejected" : "")
                            </td>

                            <td>@InspectionReport.InspectionDate.ToString("MMM dd, yyyy")</td>
                            <td>@InspectionReport.IssueDate.ToString("MMM dd, yyyy")</td>

                            @{ 
                               VAILCertificates.DAL.UserDAL userDAL = new VAILCertificates.DAL.UserDAL();
                               VAILCertificates.DAL.Entities.User User = new VAILCertificates.DAL.Entities.User();
                               User = userDAL.GetUserStationLocation(InspectionReport.PeparedBy);                              
                             }

                            <td>@User.UserName</td>     
                            <td>@User.Office</td>
                            <td>@User.Station</td> 

                            <td>
                                @using (Html.BeginForm("GetInspectionReportDetails", "InspectionReport", FormMethod.Post, new { InspectionReportID = @InspectionReport.InspectionReportID }))
                                {
                                    @*@Html.ActionLink("View", "Edit","InspectionReport", new { id = @InspectionReport.InspectionReportID }, new { @Class = "btn btn-success" })*@
                                    @*@Html.ActionLink("View", "GetInspectionReportDetails","InspectionReport", new { id = @InspectionReport.InspectionReportID }, new { @Class = "btn btn-success" })*@
                                    <button class="btn btn-info" type="submit" id="btnReview" name="btnDownload" formaction='@Url.Action("GetInspectionReportDetails", "InspectionReport", new { InspectionReportID = @InspectionReport.InspectionReportID})'>Download Files</button>
                                    @*<a class="btn btn-primary" href="@("/Downloads/Certificates/"+ @InspectionReport.FileName)" download>Download Certificate</a>*@

                                }
                        </td>

                    </tr>
                    }
                </tbody>
            </table>

标签: c#jqueryasp.net-mvcmodel-view-controllerdatatables

解决方案


推荐阅读