返回重定向,然后调用JS函数

时间:2015-11-24 15:42:50

标签: c# jquery asp.net-mvc asp.net-mvc-3 datatables

在屏幕上显示Jquery DataTable。选择行,为该行选择新的试用日期。按下按钮并在控制器POST中更新必要的行。 if (Request.HttpMethod == "POST")一切正常。

然后我使用return RedirectToAction("Users", "AziMapOrgs");来调用更新数据表'AllOrgsDataTable'的函数,我认为它将在视图中更新jquery dataTable。但事实证明我还需要在视图中调用function setupPage()来重绘dataTable。

//controller
 public ActionResult Users(string selectedCheckBoxes, string newDate)
        {
            Models.AziMapOrgsModel orgModel = new Models.AziMapOrgsModel();

            //When Extend Trial button is pressed will be a post back so update users to new Trail End Date
            if (Request.HttpMethod == "POST")
            {
                if (selectedCheckBoxes != "" && newDate != "")
                {
                    orgModel.UpdateUserTrial(selectedCheckBoxes, newDate);
                    return RedirectToAction("Users", "AziMapOrgs");
                }
                //after new exiry date set run through code again to update table with new dates
            }

            //Display all users in dataTable and set ID to 'IDColumn' in jquery dataTable
            ViewModels.AziMapOrgsVM orgViewModel = new ViewModels.AziMapOrgsVM();
            orgViewModel.AllOrgsDataTable = orgModel.GetOrganisations();
            orgViewModel.IDColumn = "ID";

            return View(orgViewModel);
        }

//Users View
    function SetupPage() {
    //draw dataTable
    var table = $('#OrgTable').DataTable();
    if (table.length > 0) {
        table.DataTable({
            "bSort": false,
            "sScrollX": true,
            "bLengthChange": false,
            "scrollY": "75%",
            "scrollCollapse": true,
            "paging": false,
            "oLanguage": {
                "sZeroRecords": "No such record exists"
            },
            "columnDefs": [
            { type: "OrgFreeTrialEnd", targets: 0 }
            ]
        });
    }
    table.draw();

0 个答案:

没有答案