【发布时间】:2018-09-13 07:06:20
【问题描述】:
lam 试图将答复保存到数据库 这是我的html表单,
<div id="replyform" class="card my-4 d-none">
<h5 class="card-header">Cevap Yaz:</h5>
<div class="card-body">
<form>
<div class="form-group">
<textarea id="replytext" name="replytext" typeof="text" class="form-control" rows="3"></textarea>
</div>
<button type="submit" id="sendreply" name="sendreply" class="btn btn-primary">Cevap Yaz</button>
</form>
</div>
</div>
这是我的家庭控制器操作代码
public JsonResult ReplyComment(string replycomment, int articleid,int commentid)
{
var UserId = Session["UserId"];
if (replycomment == null)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
db.ReplyComments.Add(new ReplyComment
{ UserId = Convert.ToInt32(UserId), ArticleId = articleid, CommentId=commentid, Paragraph = replycomment, Date = DateTime.Now });
db.SaveChanges();
return Json(false, JsonRequestBehavior.AllowGet);
}
我的 ajax 代码在这里
<script type="text/javascript">
$(document).ready(function () {
$("#sendreply").click(function () {
var r_comment = $("#replytext").val();
var r_commentid = $(".astar").val();
$.ajax({
cache: false,
url: '@Url.Action("ReplyComment","Home")',
contentType: "application/json; charset=utf-8",
data: { replycomment: r_comment, articleid:@Model.ArticleId, commentid: r_commentid },
type: 'POST',
dataType: 'json',
success: function (data) {
alert("İşlemOkey");
}
});
});
})
我无法使用此代码调用回复评论操作
【问题讨论】:
-
您需要一种方法来防止
submit按钮的默认行为。例如,您可以使用preventDefault来做到这一点...您可以将这一行$("#sendreply").click(function () {替换为这一行 @ 987654327@ -
我是新手,请你写完整的ajax代码
-
只是一个替换.....用新的替换你当前的行,然后再试一次!
-
İt did not work 问题是一样的
-
我正在使用不同的表单正常评论和回复评论当用户单击回答按钮时,如果您认为我使用相同的表单进行两个操作,则会打开一个新表单
标签: html ajax asp.net-mvc view controller