私はプログラミングが初めてで、クリックすると前のページに戻るボタンがあります。前のページに戻るボタンの代わりに、そのボタンに現在の情報を印刷させる方法は?
これが私のPrintIndexViewModelクラスです
using NavisionStore.Domain.Entities;
namespace NavisionStore.WebUI.Models
{
public class PrintIndexViewModel
{
public Print Print { get; set; }
public string ReturnUrl { get; set; }
}
}
これが私のプリントコントローラーです
namespace NavisionStore.WebUI.Controllers
{
public class PrintController : Controller
{
private IProductRepository repository;
public PrintController(IProductRepository repo)
{
repository = repo;
}
public ViewResult Index(string returnUrl)
{
return View(new PrintIndexViewModel
{
Print = GetPrint(),
ReturnUrl = returnUrl
});
}
public RedirectToRouteResult AddtoPrint(int id, string returnUrl)
{
Product product = repository.Products
.FirstOrDefault(p => p.Id == id);
if (product != null)
{
GetPrint().AddItem(product, 1);
}
return RedirectToAction("Index", new { returnUrl });
}
public RedirectToRouteResult RemoveFromPrint(int id, string returnUrl)
{
Product product = repository.Products
.FirstOrDefault(p => p.Id == id);
if (product != null)
{
GetPrint().RemoveLine(product);
}
return RedirectToAction("Index", new { returnUrl });
}
private Print GetPrint()
{
Print print = (Print)Session["Print"];
if (print == null)
{
print = new Print();
Session["Print"] = print;
}
return print;
}
}
}
これがビューprintindexveiwmodelです
@model NavisionStore.WebUI.Models.PrintIndexViewModel
@{
ViewBag.Title = "Bag Labels: Your Print";
}
<h2>Caplugs West</h2>
<table width="90%" align="center">
<thead><tr>
<th align="center">PN:</th>
<th align="center">QTY:</th>
<th align="center">B#</th>
</tr></thead>
<tbody>
@foreach(var line in Model.Print.Lines) {
<tr>
<td align="center">@line.Product.PartName</td>
<td align="center">@line.Product.Quantity</td>
<td align="center">@line.Product.BagNumber</td>
</tr>
}
</tbody>
</table>
<p align="center" class="actionButtons">
<a href="@Model.ReturnUrl">Print</a>
</p>