如果模型对话框已打开,则无法下载文件
Not able to download the file if a model dialog is already opened
We opened an popup by using jquery extension.Our requirement is to
download a file on click of button present in popup. My code is like
this:-
JS code:-
showModalData: function (obj) {
var url = OC.MVC.util.getLink("Employee", "GetDetail");
$.ajax({
url: url,
type: 'GET',
success: function (result) {
$.modal(result);//open the modal popup
},
error: function (err) {
alert(err.responseText);
}
});
}
Controller code:-
public virtual ActionResult GetDetail(Employee model)
{
return PartialView(model);
}
View:-
<div>
@Html.Raw(Html.Button("btnDownload", "Download").ToString())
<div>
Now on click of Download I have to download the file for this code
is:-
public ActionResult Download()
{
byte[] fileBytes = System.IO.File.ReadAllBytes(@"c:\New\note.txt");
string fileName = "note.txt";
return (File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
}
On click of download button it will call the Download action defined
in controller.Now return (File(fileBytes,
System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); should
opens the save dialog to select the path to save the document.But
it is not opening the save dialog box.It is also not showing error
and nothing is happening.Note: Download button present in Modal Popup.
您需要确保您的下载操作是通过来自浏览器的正常 HTTP 请求调用的,而不是通过 JavaScript 发起的 AJAX 调用调用的。
We opened an popup by using jquery extension.Our requirement is to download a file on click of button present in popup. My code is like this:-
JS code:-
showModalData: function (obj) {
var url = OC.MVC.util.getLink("Employee", "GetDetail");
$.ajax({
url: url,
type: 'GET',
success: function (result) {
$.modal(result);//open the modal popup
},
error: function (err) {
alert(err.responseText);
}
});
}
Controller code:-
public virtual ActionResult GetDetail(Employee model)
{
return PartialView(model);
}
View:-
<div>
@Html.Raw(Html.Button("btnDownload", "Download").ToString())
<div>
Now on click of Download I have to download the file for this code is:-
public ActionResult Download()
{
byte[] fileBytes = System.IO.File.ReadAllBytes(@"c:\New\note.txt");
string fileName = "note.txt";
return (File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
}
On click of download button it will call the Download action defined in controller.Now return (File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); should opens the save dialog to select the path to save the document.But it is not opening the save dialog box.It is also not showing error and nothing is happening.Note: Download button present in Modal Popup.
您需要确保您的下载操作是通过来自浏览器的正常 HTTP 请求调用的,而不是通过 JavaScript 发起的 AJAX 调用调用的。