@using (Html.BeginForm("publish_comment", "comment"))
{
@ViewBag.comment_txt
}
通过submit向页面提交事件,将参数传到controller,再传给service方法,在service中向数据库中插入数据,代码:
public static void PublishComment(Models.CommentResult model)
{
if (model.comment_txt == null)
{
}
using (Models.blogEntities edm = new Models.blogEntities())
{
int rows = edm.blog_comment.Count() + 1;
edm.blog_comment.AddObject(new Models.blog_comment()
{
comment_id = rows,
blog_id = model.blog_id,
comment_txt = model.comment_txt,
comment_time = System.DateTime.Now,
comment_enable = true,
comment_auth = model.comment_auth
});
edm.SaveChanges();
}
}
也不知道说的对不对,但终究是解决了,请多指正!