public ActionResult Create(RssSource rssSource) { if (ControllerContext.HttpContext.Request.IsAjaxRequest()) { if (ModelState.IsValid) { repository.Add(rssSource); var result = new HandlerResult { IsSuccess = true, Message = "添加RSS源成功" }; return Json(result); } else { var result = new HandlerResult { IsSuccess = false, Message = "添加RSS源失败" }; return Json(result); } } else { if (ModelState.IsValid) { var flag = repository.Add(rssSource); return Redirect("Index"); } else { return View(rssSource); } } }
public ActionResult Write(Article article) { var a = TryValidateModel(article); NLog.LogManager.GetCurrentClassLogger().Debug("是否通过====" + a); if (ModelState.IsValid) { article.PubDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); var flag = repository.Add(article); HandlerResult result = null; if (flag) { result = new HandlerResult { IsSuccess = true, Message="操作成功" }; } else { result = new HandlerResult { IsSuccess = false, Message = "操作失败" }; } return View("Index"); } return View(article); }