我有一个按钮,它通过在控制器中运行保存功能来保存表单。该控制器的形式为:如何使用一种控制器方法返回FileResult和View
[HttpPost]
public ActionResult Save(ViewModel model)
{
Save(model);
var newModel = new ViewModel();
return View(Index, newModel);
}
,我有以下形式的DownloadFile功能
public FileResult DownloadReceipt(int reportId)
{
filebytes = CreateFile(reportid);
return File(filebytes, MediaTypeNames.Application.Pdf, "file name");
}
我希望能够允许用户下载使用第二功能,同时该文件使用第一个函数将用户重定向到索引。单击保存按钮时,第一个函数被调用。有没有一种方便的方法可以使用该按钮将文件下载到用户计算机上,同时仍然重定向到所需的视图。目前下载文件功能不会在任何地方被调用。
您无法同时返回视图和文件。您可以通过链接返回视图以下载文件,或者通过javascript调用下载。 – DavidG
在'onsuccess'内重定向? –