该页面通过JavaScript向控制器操作发送带有过滤器值的请求:
function ItemListModel(row) {
var self = this;
self.Date = row[0];
self.Rank = row[1];
self.UserID = row[2];
self.Last = row[3];
self.First = row[4];
self.Middle = row[5];
self.Serial = row[6];
self.ECN = row[7];
self.MAC = row[8];
self.Clinical = row[9];
self.Make = row[10];
self.Model = row[11];
self.Dept = row[12];
}
function Export() {
var oSettings = oTable.fnSettings();
var arr = new Array();
$("tfoot input").each(function (i) {
var test = $(this).val();
arr.push(test);
});
var model = [];
model = new ItemListModel(arr);
window.location.href = "/Inventory/ExportSheet?model=" + JSON.stringify(model);
}
行动是:
public void ExportSheet(string model)
{
ItemsListModel reportmodel = new ItemsListModel();
if (model != null)
{
JavaScriptSerializer serl = new JavaScriptSerializer();
reportmodel = (ItemsListModel)serl.Deserialize(model, typeof(ItemsListModel));
}
DataTable dt = ReportsRepository.GetItemsListParms(CleanReportParms(reportmodel));
dt.Columns.Add("DateIssued");
foreach (DataRow row in dt.Rows)
{
DateTime date = row.Field<DateTime>("Date Issued");
string newdate = date.ToShortDateString();
row.SetField("DateIssued", newdate);
}
dt.Columns.Remove("Date Issued");
DumpExcel(dt, "itemlist");
}
我正在使用EPPlus创建一个电子表格以便下载到浏览器。这在我的开发盒上非常有效,但是一旦部署,我就会收到这个错误:
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make sure
that it is spelled correctly.
Requested URL: /Inventory/ExportSheet
答案 0 :(得分:1)
您是否将应用程序部署到IIS中的网站根目录?这一行要求您:
window.location.href = "/Inventory/ExportSheet?....
我建议使用与页面相关的网址,以便您的应用可以部署在网站根目录下的某个位置。这将以不同的方式实施,具体取决于您如何为JS提供服务。如果它位于服务器端页面上的script
标记中,并且您想要路由到MVC操作:
window.location.href = 'Url.Action("ExportSheet")?model=' + JSON.stringify(model);
应该有用。