ASP.NET MVC5注释系统错误

时间:2017-12-27 06:17:30

标签: asp.net asp.net-mvc-5

使用局部视图显示在屏幕上。

在详细方法中强制部分视图。

<div>
                        @Html.Partial("_CommentView", new ViewDataDictionary { { "comments", ViewBag.articleComment } })
                    </div>

但我现在只是评论。

我想说出时间。

帮我弄清楚在哪里解决它。

我想在屏幕上显示姓名,内容和时间。

但现在我只得到内容。

我可以在哪里修改代码以获得我想要的结果?

我是否需要在详细方法中添加另一个细节?

BoardController

[HttpGet]
        public ActionResult Detail(int aidx)
        {
            ArticlesEditViewModel vm = new ArticlesEditViewModel();

            Articles article = db.Articles.Where(c => c.ArticleIDX == aidx).FirstOrDefault();
            List<ArticleFiles> files = db.ArticleFiles.Where(c => c.ArticleIDX == aidx).OrderBy(o => o.UploadDate).ToList();
            vm.Article = article;
            vm.Files = files;

            var comments = (from k in db.ArticleComments
                            where k.ArticleIDX == aidx
                            select k.Comments);

            ViewBag.articleComment = comments;


            article.ModifyMemberID = User.Identity.Name;
            ViewBag.article = article.ModifyMemberID;

            ViewData["id"] = 1;


            return View(vm);
        }

        [HttpPost]
        public JsonResult CommentsAdd(ArticleComments articleComments)
        {
            try
            {
                if (!String.IsNullOrEmpty(articleComments.Comments) && !String.IsNullOrEmpty(articleComments.ArticleIDX.ToString()))
                {

                    articleComments.RegistDate = DateTime.Now;
                    articleComments.MemberID = User.Identity.Name;
                    // save to database here
                    db.ArticleComments.Add(articleComments);
                    db.SaveChanges();
                    string result = "저장이 완료되었습니다.";
                    return Json(result);
                }
                else
                {
                    string result = "내용을 작성해주세요.";
                    return Json(result);
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }

_CommentView:

@using HeadHomePage1.Models;

@model HeadHomePage1.Models.ArticleComments

@{
    ViewBag.articleComment = ViewData["comments"];
    ViewBag.Comment = "Comment : ";
    ViewBag.article = ViewData["article.ModifyMemberID"];
}


<div class="container">
    <div class="page-header">
        <h4 style="margin-right:85%">Comments:</h4>
    </div>
</div>
@foreach (var comments in ViewBag.articleComment)
{
    <div class="well">
        <p>@comments</p>
    </div>
}

 Model:

public partial class ArticleComments
    {
        [Key]
        [Column(Order = 0)]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int ArticleIDX { get; set; }

        [Key]
        [Column(Order = 1)]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id { get; set; }

        [Required]
        [StringLength(20)]
        public string MemberID { get; set; }

        [Column(TypeName = "text")]
        public string Comments { get; set; }

        public DateTime? RegistDate { get; set; }
    }

0 个答案:

没有答案