public override ActionResult Execute() { var modelState = ViewData.ModelState; if (IsPost) { try { System.Web.Helpers.AntiForgery.Validate(); } catch (Exception) { throw new HttpException(500, "AntiForgery validate failed!"); } var textContent = Request.Form.ToTextContent(); var comment = new Comment(textContent) { Published = true }; ViewData["Comment"] = comment; //TODO: validate content //TODO: Add Content if (modelState.IsValid) { //... //TODO: Update User ViewData["Comment"] = null; return null; } } return null; }
public ActionResult AddComment(FormCollection formCollection) { AntiForgery.Validate(); var textContent = formCollection.ToTextContent(); var comment = new Comment(textContent) { Published = true }; var data = new JsonResultData(ModelState); data.RunWithTry((resultData) => { ToolkitDemoContext.Current.CommentService.Add(comment); resultData.Model = ControllerContext.RenderView("Article.CommentItem", comment); resultData.AddMessage("Add comment success!".RawLabel("AddSuccess", "Comment").ToString()); resultData.ReloadPage = false; }); return Json(data); }