public IActionResult Single(SingleModel model) { int userid = CurrentUser().CurrentUserId; string content = model.Post.Body; int blogid = Convert.ToInt32(HttpContext.Request.Query["id"]);//在ajax里好像没有用 blogService.AddPost(content, userid, blogService.GetById(blogid.ToString())); blogService.SendMessage(blogService.GetById(blogid.ToString()), userService.GetById(CurrentUser().CurrentUserId.ToString())); //添加的逻辑没问题,只是再显示这个页面的时候 关于文章的Model内容没了 所以显示不出 //此时的Model返回去好像没了之前取到的Blog的关联User //应该是Model的问题 //解决方式应该是Get Post Redirect 方式 还有Ajax20191206 #region 关于传回Model 其他属性为空 解决方式未定 已解决20191126 使用Redirect //model.BlogTime = blogService.GetById(HttpContext.Request.Query["id"]).CreatedTime; //model.Title = blogService.GetById(HttpContext.Request.Query["id"]).Title; //model.Body = blogService.GetById(HttpContext.Request.Query["id"]).Body; //model.BlogAuthor = blogService.GetById(HttpContext.Request.Query["id"]).Author.UserName; //model.Posts = blogService.GetById(HttpContext.Request.Query["id"]).Posts; #endregion return(Redirect("/Blog/Single?id=" + blogid.ToString())); //return View(model); }
public IActionResult AddPost(int blogId, [FromBody] Post post) { var newPost = blogService.AddPost(blogId, post); return(Created($"/api/blogs/{blogId}/posts/{newPost.PostId}", newPost)); }
public async Task AddPost([FromBody] AddPostRequest request) { await _blogService.AddPost(request); }