ASP.NET中的较新版本(使用Framework)。我需要将在一个控制器(如我的数据过滤器)中生成并初始化的datetime值传输到另一个控制器。
我需要传输值start
和end
我试图使用Cookie /会话,如:
我检查了ViewBag.Start / ViewBag.End值,它们不为null。但是他们没有显示结果。
public actionResult Index( int? id,DateTime? start,DateTime? end)
{
string j = id.ToString();
HttpContext.Response.Cookies["id"].Value = j;
string startS = start.ToString();
string endS = end.ToString();
HttpContext.Response.Cookies["start"].Value = startS;
HttpContext.Response.Cookies["end"].Value = endS;
Session["start"] = HttpContext.Response.Cookies["start"].Value;
Session["end"] = HttpContext.Response.Cookies["end"].Value;
}
它可能会将值传输到另一个控制器。
public actionResult Confirm()
{
int Id = int.Parse(Session["id"].ToString());
var aps = from s in dbshow.GetList()
select s;
ViewBag.Start = Session["start"].ToString();
ViewBag.End = Session["end"].ToString();
aps = aps.Where(s => s.ApartmentId == Id);
return View(aps);
}
还有id参数-它几乎可以正确工作(有时无法从会话转换为int值)。
但是日期无效。