Asp.net mvc 我无法在asp.net MVC 3.0 razor中下载文件(System.Security.SecurityException:该程序集不允许部分受信任的调用者)
我正在我的控制器中创建一个函数,可以为我下载文件。但它不能在线工作。当我在线部署我的项目时,我遇到了这个错误 请帮我解决这个问题Asp.net mvc 我无法在asp.net MVC 3.0 razor中下载文件(System.Security.SecurityException:该程序集不允许部分受信任的调用者),asp.net-mvc,asp.net-mvc-3,razor,Asp.net Mvc,Asp.net Mvc 3,Razor,我正在我的控制器中创建一个函数,可以为我下载文件。但它不能在线工作。当我在线部署我的项目时,我遇到了这个错误 请帮我解决这个问题 /> 在jquery中,我使用了这个 $(文档).ready(函数(){ $(“#导出excel”)。单击(函数(事件){ //$(this.attr('href',“/Home/ExportToExcelCombine?select_rows=“+$('#select_rows').val()); var val=$(“#选择_行”).val(); $(this
/>
在jquery中,我使用了这个
$(文档).ready(函数(){
$(“#导出excel”)。单击(函数(事件){
//$(this.attr('href',“/Home/ExportToExcelCombine?select_rows=“+$('#select_rows').val());
var val=$(“#选择_行”).val();
$(this.attr('href','@Url.Action(“ExportToExcelCombine”,“Home”)?选择_rows='+val);
}); });
谢谢我正在controller中使用此代码导出到excel。我正在使用NPOI dll导出到excel
public ActionResult ExportToExcelCombine(字符串选择_行)
{
var工作簿=新的HSSF工作簿()
使用(var exportData=new MemoryStream())
{
工作簿。写入(导出数据)
TempData[“Message”]=“Excel报表创建成功!”
}
鉴于此,我正在使用
在jquery中,我使用
$(文档).ready(函数(){$(“#导出_excel”)。单击(函数
(event){/$(this.attr('href',
“/Home/ExportToExcelCombine?select_rows=“+$('#select_rows').val()”;
var val=$('#select_rows').val();$(this.attr('href'),
'@Url.Action(“ExportToExcelCombine”,“Home”)?选择_rows='+val);});
}))
我正在使用$('#select_rows').val()对于隐藏字段值,当我在Jtable中选择一些行时,该值会发生更改。请显示您的代码。否则,有人能提供帮助吗?请检查代码说明。我已编辑了我的请求,如果您显示操作的代码,则会有所帮助。错误是服务器端错误,因此这就是问题所在。jQuery所做的就是调用该操作n、 请检查我提到的每个代码,以及我正在使用的所有代码。
<a id="export_excel" href='#'>
<img id="export" src='@Url.Content("~/images/buttons/get_report.jpg")' alt="Get Report"
string[] test = select_rows.ToString().Split(';');
var sheet = workbook.CreateSheet("Summary");
int row_index = 0;
var excelnewrow = sheet.CreateRow(row_index);
excelnewrow.CreateCell(0).SetCellValue("Entity Name");
row_index++;
excelnewrow = sheet.CreateRow(row_index);
excelnewrow.CreateCell(0).SetCellValue("Type of Entity");
row_index++;
excelnewrow = sheet.CreateRow(row_index);
excelnewrow.CreateCell(0).SetCellValue("Industry");
row_index++;
excelnewrow = sheet.CreateRow(row_index);
excelnewrow.CreateCell(0).SetCellValue("Country");
row_index++;
excelnewrow = sheet.CreateRow(row_index);
excelnewrow.CreateCell(0).SetCellValue("");
row_index++;
excelnewrow = sheet.CreateRow(row_index);
HSSFCellStyle style_summary_color = workbook.CreateCellStyle();
// cell background
style_summary_color.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.BLACK.index;
style_summary_color.FillPattern = HSSFCellStyle.SOLID_FOREGROUND;
// font color
HSSFFont font_summary_color = workbook.CreateFont();
font_summary_color.Color = NPOI.HSSF.Util.HSSFColor.WHITE.index;
style_summary_color.SetFont(font_summary_color);
excelnewrow.RowStyle = style_summary_color;
excelnewrow.CreateCell(0).SetCellValue("Facebook");
excelnewrow.GetCell(0).CellStyle = style_summary_color;
row_index++;
excelnewrow = sheet.CreateRow(row_index);
excelnewrow.CreateCell(0).SetCellValue("");
string saveAsFileName = string.Format("Report-{0:d}.xls", DateTime.Now).Replace("/", "-");
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName));
Response.Clear();
Response.BinaryWrite(exportData.GetBuffer());
Response.End();
return File(saveAsFileName, "application/vnd.ms-excel", saveAsFileName);
}
//return File(buffer, "application/vnd.ms-excel");
return RedirectToAction("ExcelPackage");