У меня есть проект в. Net ядре, которое генерирует ID-карту. Все отлично работает, когда я печатаю удостоверение личности для одного ученика, но у меня проблемы с печатью нескольких удостоверений личности.
У меня есть метод get в моем контроллере следующим образом:
[HttpGet]
[AllowAnonymous]
public IActionResult BulkCard()
{
//values = ViewBag.Cards;
var values = (object[])TempData["students"]; //This retrieves all students that has been selected to print their ID Card
ViewBag.Cards = values.ToArray();
var designtemplate = _context.Settings.First();
if (designtemplate.CardTemplate == 1)
{
ViewBag.Template = "1";
}
else if (designtemplate.CardTemplate == 2)
{
ViewBag.Template = "2";
ViewBag.TemplateView = "This is template 2";
}
else if (designtemplate.CardTemplate == 3)
{
ViewBag.Template = "3";
ViewBag.TemplateView = "This is template 3";
}
else
{
return RedirectToAction("CardSettings", "Settings");
}
var model = new ModelClasses();
foreach (var item in values)
{
model.Students = _context.Students.ToList();
model.Student = _context.Students.Include(c => c.Department).Include(c => c.Department.Faculty).Include(c => c.ProgramType).Include(c => c.ClassLevels).Include(c => c.Session).ToList().FirstOrDefault(c => c.Id == Convert.ToInt32(item));
ViewBag.Students = _context.Students.Include(c => c.Department).Include(c => c.Department.Faculty).Include(c => c.ProgramType).Include(c => c.ClassLevels).Include(c => c.Session).ToList().Where(c => c.Id == Convert.ToInt32(item)).ToList();
var surname = model.Student.Surname;
var firstname = model.Student.FirstName;
var middleName = model.Student.MiddleName[0];
var fullname = surname + " " + firstname + " " + middleName + ".";
ViewBag.FullName = fullname;
ViewBag.MatricNumber = model.Student.MatricNumber;
ViewBag.Department = model.Student.Department;
ViewBag.Faculty = model.Student.Faculty;
ViewBag.Passport = "/Uploads" + "/Passport/" + model.Student.Passport;
ViewBag.Signature = "/Uploads" + "/Signature/" + model.Student.Signature;
var qrdata = model.Student.QRCodeData.ToString().Replace("/", "");
using (MemoryStream ms = new MemoryStream())
{
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrdata, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
using (Bitmap bitMap = qrCode.GetGraphic(20))
{
bitMap.Save(ms, ImageFormat.Png);
ViewBag.QRCodeImage = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
}
}
}
return View(model);
}
И в моем следующий вид:
@foreach (var item in ViewBag.Students)
{
@if (ViewBag.Template == "1")
{
<table>
<tr>
<td>
BULK CARD PRINTING
<img src="@ViewBag.QRCodeImage" class="qrcode">
</td>
</tr>
</table>
@*<table>
<tr>
<td>
<div class="wrapper">
<div class="container">
<div style="position: absolute;color: lightgray;opacity: 0.05;font-size: 3em;width: 50%;top: 25%; left: 80px;text-align: center;z-index: 0;background-attachment: fixed;"><img src="~/img/fedpolel-Logo.png" width="150" /></div>
<img src="~/Uploads/Passport//@item.Passport" alt="" class="profile-img">
<img src="~/img/fedpolel-Logo.png" class="logo" />
<img src="@ViewBag.QRCodeImage" class="qrcode">
<div class="content">
<table>
<tr>
<td>
<div class="title">
<h4>THE FEDERAL POLYTECHNIC</h4>
<span>ILE OLUJI, ONDO STATE.</span>
</div>
<div class="sub-content">
<center>
<h1>@item.FullName</h1>
</center>
<p>@item.MatricNumber</p>
</div>
<div class="vr"></div>
<div class="vr-right"></div>
<div class="data">
<div class="inner-data">
<span>Gender</span>
<p>@item.Gender<p />
<br>
<span>Session</span>
<p class="session">@item.Session.SessionName</p>
</div>
<div class="inner-data2">
<span>Level</span>
<p>@item.ClassLevels.ClassLevel</p>
<span>Department</span>
<p>@item.Department.DepartmentName</p>
<span>Faculty</span>
<p>@item.Department.Faculty.FacultyName</p>
</div>
<div class="inner-data3">
<div class="hr"></div>
<p><img src="@ViewBag.Signature" width="50" /></p>
<div class="paragra">Signature</div>
</div>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
</table>*@
}
else if (ViewBag.Template == "2")
{
@ViewBag.TemplateView
}
else if (ViewBag.Teplate == "3")
{
@ViewBag.TemplateView
}
else
{
@ViewBag.NoTemplateView
}
}
Этот код возвращает данные только для последнего учащегося.
Моя задача: если у меня предварительно выбрано 5 учеников, я хочу вернуть данные пяти учеников. Пожалуйста, как мне этого добиться?