我有一个编辑操作来编辑我的
议论
型号:
public partial class Comment
{
[DisplayName("Ø´ÙØ§Ø³Ù ÙØ¸Ø±")]
public int Id { get; set; }
[Required(ErrorMessage = "Ù
ØªÙ ÙØ¸Ø± را ÙØ§Ø±Ø¯ Ú©ÙÛØ¯")]
[DisplayName("Ù
ØªÙ ÙØ¸Ø±")]
public string CommentText { get; set; }
[DisplayName("تعداد Ù¾Ø³ÙØ¯Ûد٠")]
public long LikeCount { get; set; }
[DisplayName("تعداد ÙÙ¾Ø³ÙØ¯ÛدÙ")]
public long DisLikeCount { get; set; }
[DisplayName("ØªØ§Ø±ÛØ® Ø§ÙØªØ´Ø§Ø± ")]
public System.DateTime PublishDate { get; set; }
[DisplayName("ÙØ¶Ø¹Ûت ÙÙ
Ø§ÛØ´ ")]
public string Visible { get; set; }
[DisplayName("ÙØ§Ù
Ú©Ø§Ø±Ø¨Ø±Û ")]
public string AutherUserName { get; set; }
[DisplayName("Ø´ÙØ§Ø³Ù ÙØ¸Ø±Ø§ØµÙÛ")]
public Nullable<int> CommentFKId { get; set; }
[DisplayName("Ø´ÙØ§Ø³Ù کاربر")]
public Nullable<int> StudentId { get; set; }
[DisplayName("Ø´ÙØ§Ø³Ù Ù
ØØªÙا ")]
public Nullable<int> ContentId { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
public virtual Comment Comment1 { get; set; }
public virtual Student Student { get; set; }
public virtual Content Content { get; set; }
}
我的模型中有很多列,但在编辑操作中,我只需要编辑其中的一些列。
因此,我的Postback编辑操作如下:
[HttpPost]
public ActionResult Edit(Comment comment, FormCollection form)
{
//comment.AutherUserName = "admin";
//comment.LikeCount = 0;
if (ModelState.IsValid)
{
TryUpdateModel(comment, new string[] {"CommentText", "Visible"});
obj.Update(comment);
obj.Save();
}
return RedirectToAction("Index", "Comment", new { contentID = form["ContentId"].ToString() });
}
如你所见,我想更新
注释文本
和
看得见的
。但此代码不会更新我的模型。它不会返回任何错误
这是我的
使现代化
方法:
public void Update(Comment comment)
{
_dbcontext.Entry(comment).State = EntityState.Modified;
}
我的保存功能:
public void Save()
{
_dbcontext.SaveChanges();
}
顺致敬意,