1
Code of the contorller
public JsonResult InsertComment(string description, int postID)
{
try
{
Comment comment = new Comment
{
Content = description,
DataCommented = DateTime.Now,
PostID = postID,
UserID = User.Identity.GetUserId()
};
db.Comments.Add(comment);
db.SaveChanges();
}
catch (Exception)
{
}
return Json(comment, JsonRequestBehavior.AllowGet);
}
Json code
$(function () {
if (CommentInput.value != "") {
$.ajax({
type: 'GET',
url: '/Comment/InsertComment',
dataType: 'Json',
cache: false,
async: true,
data: { postID: CommentInput.getAttribute('data-postid'), description: CommentInput.value },
success: function () {
alert('oi');
}
});
CommentInput.value = "";
}
});
The comment is inserted normally, but does not execute the alert
in the sucess
, what is wrong?
worked, would you have any explanation about that to add? I will give the answer as correct in 8 minutes.
– Ivan Ricardo Lopes
Yes I will put! if ta returning null then there was no success
– user6026