我将 DateTime 值从使用的视图传递回[HttpPost]
控制器。我在控制器中有另一种方法,我也想要 HttpPost 方法的结果。或者我可以将 HttpPost 传递回视图。
我想要的是从 HttpPost 方法的表单中显示 LINQ 的值。
我使用的填充视图的原始方法如下。
public ActionResult Index()
{
ViewBag.Message = "Real Time Production";
DateTime ShiftStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
DateTime StartShift = ShiftStart.AddHours(7);
DateTime EndDate = StartShift.AddDays(1);
try
{
var PumaProduct =
new
{
PumaCastGood =
(from item in db.tbl_dppITHr
where item.ProductionHour >= StartShift && item.ProductionHour <= EndDate
select item).Sum(x => x.PumaCastGross) ?? 0,
PumaScrap =
(from item in db.tbl_dppITHr
where item.ProductionHour >= StartShift && item.ProductionHour <= EndDate
select item).Sum(x => x.PumaScrap) ?? 0,
PumaMachined =
(
from item in db.tbl_dppITHr
where item.ProductionHour >= StartShift && item.ProductionHour <= EndDate
select item).Sum(x => x.PumaMachined) ?? 0,
PumaHeatTreat =
(
from item in db.tbl_dppITHr
where item.ProductionHour >= StartShift && item.ProductionHour <= EndDate
select item).Sum(x => x.ATIPuma) ?? 0,
PumaShipped =
(
from item in db.tbl_dppITHr
where item.ProductionHour >= StartShift && item.ProductionHour <= EndDate
select item).Sum(x => x.PumaShipped) ?? 0,
};
ViewData["PumaCastGood"] = PumaProduct.PumaCastGood;
ViewData["PumaCastScrap"] = PumaProduct.PumaScrap;
ViewData["PumaMachined"] = PumaProduct.PumaMachined;
ViewData["PumaShipped"] = PumaProduct.PumaShipped;
ViewData["PumaHeatTreat"] = PumaProduct.PumaHeatTreat;
以下是我想传递给 ActionResult 索引或与 Index 方法中的项目一起传递给视图的 HttpPost 方法。
[HttpPost]
public ActionResult GetSigmaDateInfo(string dp)
{
DateTime SelectedDate = Convert.ToDateTime(dp);
DateTime SelectedDateDayShiftStart = SelectedDate.AddHours(7);
DateTime SelectedDateDayShiftEnd = SelectedDate.AddHours(19);
var SigmaData =
from n in db.tbl_dppITHr
where n.ProductionHour >= SelectedDateDayShiftStart
where n.ProductionHour <= SelectedDateDayShiftEnd
select n;
return View();
}
我已经尝试过在方法之间传递方法值的普通 C# 方法。