public ActionResult AddTest() { ITestBLL testBLL = new TestManager(); Test test = new Test(); test.TestName = Request["TestName"]; test.TestNum = Convert.ToInt32(Request["TestNum"]); test.TestEndTime = Convert.ToDateTime(Request["TestEndTime"]); var time = DateTime.Now.ToLocalTime(); if (test.TestEndTime <= DateTime.Now.ToLocalTime()) { return(Content("<script>alert('结束时间不能小于当前时间!');history.go(-1);</script>"));//不刷新退回页面 } if (testBLL.AddEntity(test)) { return(Redirect("/Home/Test")); } else { return(Content("<script>alert('添加失败!');window.location.href='/Home/AddTest';</script>"));//刷新页面 } }