我在GetCoupons(int studentId)
中有一个操作CouponsController
,该操作会返回包含所选学生优惠券的视图。这是我的代码:
[HttpGet]
public ActionResult GetCoupons(int studentId)
{
var coupons = _context.Coupons
.Where(c => c.StudentId == studentId)
.Include(s => s.Student)
.ToList();
return View("Print", coupons);
}
View Print.cshtml如下:
@modelIEnumerable<admin.Models.Coupons>
@foreach (var coupon in Model)
{
<div class="col-sm-3">
<div class="panel-body">
<div class="list-group">
<div class="list-group-item">
<i class="fa fa-2x fa-building-o pull-left"></i>
<label>Name</label>
<h4 class="list-group-item-heading">@coupon.Student.Name</h4>
</div>
<div class="list-group-item">
<label>Classe De:</label>
<h4 class="list-group-item-heading">@coupon.Student.ClasseId</h4>
</div>
<div class="list-group-item">
<label>No De Coupon</label>
<h4 class="list-group-item-heading">@coupon.CouponNumber</h4>
</div>
<div class="list-group-item">
<label>Code De Validation</label>
<h4 class="list-group-item-heading">@coupon.ValidationCode</h4>
</div>
<div class="list-group-item">
<label>Cours De</label>
<h4 class="list-group-item-heading"></h4>
</div>
<div class="list-group-item">
<label>Annee en cours</label>
<h4 class="list-group-item-heading">@DateTime.Now.Year</h4>
</div>
<div class="list-group-item">
<label>Signature</label>
<h4 class="list-group-item-heading"></h4>
</div>
</div>
</div>
</div>
}
<div class="row ">
<a href="@Url.Action("PrintToPdf","Coupons")" class="btn btn-default"><i class="fa fa-print"></i> Imprimer</a>
</div>
点击链接,通过PrintToPdf
上的CouponsController
操作以PDF格式打印页面时,会返回一个空白页面。 PrintToPdf
行动如下:
public ActionResult PrintToPdf()
{
return new ActionAsPdf("GetCoupons");
}
我不知道自己哪里做错了。我已经坚持了一个星期了
答案 0 :(得分:1)
您应该更改PrintToPdf
方法以获取studentId
,并传递它:
[HttpGet]
public ActionResult PrintToPdf(int studentId)
{
return new ActionAsPdf("GetCoupons", studentId);
}