【发布时间】:2020-11-03 23:11:04
【问题描述】:
我是 ASP.NET MVC 的新手,我正在尝试将两个日期之间的过滤记录打印到 PDF。我正在使用 ROTATIVA 生成 PDF,问题是 PDF 生成正确但包含所有记录,而不仅仅是两个日期的记录过滤结果。
控制器代码:
//this method is for put the list of the records on the view
public ActionResult SaleList()
{
using (inventoryEntitiesDBA dc = new inventoryEntitiesDBA())
{
return View(dc.sales.ToList());
}
}
//this method is to filter the records between start and end date
[HttpPost]
public ActionResult SaleList(DateTime start, DateTime end)
{
bool Status = false;
if(ModelStatus.IsValid())
{
using(inventoryEntitiesDBA dc = new inventoryEntitiesDBA())
{
var d = dc.sales.Where(x => x.sale_day >= start && x.sale_day <= end).ToList();
Status = true;
ViewBag.Status = Status;
return View(d);
}
}
}
//this method is to generate the PDF
public ActionResult SalesToPdf()
{
var report = new ActionAsPdf("SaleList");
return report;
}
我不知道该怎么做,欢迎提出任何建议。
*更新 ---> view:
@if (ViewBag.Status != null && Convert.ToBoolean(ViewBag.Status))
{
//this is for print if the method for filter
//the dates are called
<p align="right">
@Html.ActionLink("Generate PDF", "SalesToPdf2")
</p>
}
else
{
//this is for print if the method for filter the dates are not called
<p align="right">
@Html.ActionLink("Generate PDF", "SalesToPdf")
</p>
}
<center>
@using (Html.BeginForm("SaleList", "Sales", FormMethod.Post))
{
<span>Start Date </span> <input type="date" name="start" />
<span> End Date </span><input type="date" name="end" />
<input type="submit" value="Filter" />
}
</center>
【问题讨论】:
标签: c# asp.net-mvc razor rotativa