日期:2014-05-17 浏览次数:20481 次
public ActionResult Create(int id) { Title title = new Title() { ForumID = id }; return View(title); }
[AcceptVerbs(HttpVerbs.Post), Authorize] public ActionResult Create(Title title) { UserRepository userRepository = new UserRepository(); if (ModelState.IsValid) { try { title.CreateUserID = userRepository.GetUser(User.Identity.Name).aspnet_User.UserId; title.CreateTime = DateTime.Now; titleRepository.Add(title); titleRepository.Save(); return RedirectToAction("Details", new { id = title.TitleID }); } catch(Exception ex) { ModelState.AddRuleViolations(title.GetRuleViolations()); Response.Write(ex.Message); } } return View(title); }