当我单击“打印”按钮时,它不返回到我在代码中创建的表,该代码不返回到数据表,
这是代码,是否有人知道如何将返回File更改为datatable。当我用于下载pdf或excel表格时,我使用该返回文件,对于数据表,它将以与打印相同的方式使用。
public ActionResult PrintResult(Criteria searchInfo)
{
int total = 0;
bool isSuccess = true;
var infoMessage = string.Empty;
List<FoodModel> results = _drinkMain.GetFoodMenu(searchInfo, out total);
if (results == null || results.Count == 0)
{
isSuccess = false;
infoMessage = "No Data";
var jsonResult = new
{
isSuccess,
infoMessage,
};
return Json(jsonResult, JsonRequestBehavior.AllowGet);
}
using (var output = new MemoryStream())
{
var table = new DataTable();
table.Columns.Add("Name");
table.Columns.Add("Num");
table.Columns.Add("Total(RM)");
for (int index = 0; index < results.Count; index++)
{
var main = results[index];
if (main != null)
{
table.Columns.Add((index + 1).ToString());
table.Columns.Add(main.Name);
table.Columns.Add(main.Total)
}
}
ProfilePage first = new ProfilePage
{
ID = Guid.NewGuid(),
Date = DateTime.Now,
ModuleName = "",
ActionName = "",
};
ActivityLogger.Log(first);
var fileName = $"Profile_{Session.SystemSettings.Code}_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}";
return File(output.ToArray(), "table", fileName);
}
}