public async Task <IActionResult> Edit(int id, PostEditingBindingModel model) { if (!ModelState.IsValid) { return(View(model)); } var post = this.Context.Posts.Find(id); post.Title = model.Title; post.Body = model.Body; post.CategoryId = int.Parse(model.CategoryId); await this.Context.SaveChangesAsync(); return(Redirect("/home/index")); }
public async Task <IActionResult> Edit(int id) { var post = await this.Context.Posts.FindAsync(id); if (post == null) { return(NotFound()); } var model = new PostEditingBindingModel() { Id = post.Id, Title = post.Title, Body = post.Body, CategoryId = post.CategoryId.ToString(), Categories = GetCategories() }; return(View(model)); }