通过从Javascript调用Action Method来更新视图

Updating view by calling Action Method from Javascript

本文关键字:Method 更新 新视图 Action 调用 Javascript      更新时间:2023-09-26

我有一个javascript,如下所示:

<script>
    function GetFromDate() {    
        var dt1 = document.getElementById('fromDate').value;
        var dt2 = document.getElementById('toDate').value;
        var url = "Statistics/Excel/"  + dt1 + "!" + dt2;        
        window.location.href = url;
        return false;
    };
</script>

在控制器中,我的ActionResult是这样的:

 public ActionResult Excel(string id)
        {
              '' View Creation
               if(SomeLogic)
                  {
                         ''Excel Download Options
                  }
          return View(viewModel);
       }

虽然它可以完美地使用Excel下载选项,但它不会返回视图。有什么建议吗?有关详细信息,"viewModel"对象包含要显示的完美数据。

如果您的响应返回文件下载,那么这将被视为您的Http响应,您将无法在相同的操作中进行重定向。