// // GET: /Posts/ public ActionResult Index(int?Id) { int id = 0; if (Id != 0 && Id != null) { id = (int)Id; tbl_Post p = PostProvider.GetPost(id); List <tbl_Comment> c = CommentProvider.GetAllCommentByPostId(id); PostModel _PostModel = new PostModel { Id = p.Id, ContentMsg = p.ContentMsg, Title = p.Title, UpdatedBy = p.UpdatedBy }; List <CommentModel> _commentModel = (from temp in c select new CommentModel { Id = temp.Id, CommentText = temp.CommentText, PostId = temp.PostId, CommentedBy = temp.CommentedBy }).ToList(); PostViewModel Model = new PostViewModel(); Model.Comments = _commentModel; Model.Post = _PostModel; return(View(Model)); } else { return(View()); } }
public PartialViewResult SubmitComment(string commenttext) { List <tbl_Comment> c = CommentProvider.GetAllCommentByPostId(1); List <CommentModel> _commentModel = (from temp in c select new CommentModel { Id = temp.Id, CommentText = temp.CommentText, PostId = temp.PostId, CommentedBy = temp.CommentedBy }).ToList(); _commentModel.Add(new CommentModel { CommentText = commenttext }); return(PartialView("_Comment", _commentModel)); }