我正在使用 C# 在 ASP.NET MVC 4 中工作,我正在尝试将一个 ActionResult 方法的参数转换为一个变量,以便在另一种方法中使用。所以我有这个例如:
public ActionResult Index(int ser)
{
var invoice = InvoiceLogic.GetInvoice(this.HttpContext);
// Set up our ViewModel
var pageViewModel = new InvoicePageViewModel
{
Orders = (from orders in proent.Orders
where orders.Invoice == null
select orders).ToList(),
Callouts = (from callouts in proent.Callouts
where callouts.Invoice == null
select callouts).ToList(),
InvoiceId = ser,
InvoiceViewModel = new InvoiceViewModel
{
InvoiceId = ser,
InvoiceItems = invoice.GetInvoiceItems(),
Clients = proent.Clients.ToList(),
InvoiceTotal = invoice.GetTotal()
}
};
// Return the view
return View(pageViewModel);
}
我需要该 int ser 以某种方式变为“全局”,并且它的值可用于此方法:
public ActionResult AddServiceToInvoice(int id)
{
return Redirect("/Invoice/Index/");
}
正如您在上面的 return 语句中看到的那样,我收到一个错误,因为我没有将变量“ser”传递回 Index,但我需要它与调用操作时传递给 Index 的值相同。有人可以帮忙吗?