public ContentResult AddPost(PostName post) { string json; ModelState.Clear(); if (TryValidateModel(post)) { var id = repo.AddPost(post); json = JsonConvert.SerializeObject(new { id = id, success = true, message = "Post added successfully." }); } else { json = JsonConvert.SerializeObject(new { id = 0, success = false, message = "Failed to add the post." }); } return Content(json, "application/json"); }
public static MvcHtmlString PostLink(this HtmlHelper help, PostName pname) { return help.ActionLink(pname.TitleName, "Post", "Blognew", new { year = pname.PostedDate.Year, month = pname.PostedDate.Month, title = pname.UrlName }, new { title = pname.TitleName } ); }
public ContentResult EditPost(PostName post) { string json; ModelState.Clear(); if (TryValidateModel(post)) { repo.EditPost(post); json = JsonConvert.SerializeObject(new { id = post.Id, success = true, message = "Changes saved successfully." }); } else { json = JsonConvert.SerializeObject(new { id = 0, success = false, message = "Failed to save the changes." }); } return Content(json, "application/json"); }