سلام خدمت همه دوستان
من دارم قسمت ثبت کامنت ها رو با کد ajax اجرا می کنم اما متاسفانه کار نمی کنه و هیچ پیغام خطایی داده نمیشه....
ممنون میشم اگر با تجربیاتتون راهنماییم کنید.
//PageCommentRepository
public bool AddComment(PageComment comment)
{
try
{
db.PageComments.Add(comment);
db.SaveChanges();
return true;
}
catch (Exception)
{
return false;
}
}
------------------------------
//NewsController
public ActionResult AddComment(int id, string name, string email, string website, string comment)
{
PageComment addComment = new PageComment()
{
CreateDate = DateTime.Now,
PageID = id,
Name = name,
Email = email,
Website = website,
Comment = comment
};
pageCommentRepository.AddComment(addComment);
return null;
}
---------------------------------------
//ShowNews.cshtml
<div class="reply-form">
<h4>Leave a Reply</h4>
<p>Your email address will not be published. Required fields are marked * </p>
<form action="" method="post">
<div class="row">
<div class="col-md-6 form-group">
<input name="name" type="text" class="form-control" placeholder="Your Name*" id="txtName">
</div>
<div class="col-md-6 form-group">
<input name="email" type="text" class="form-control" placeholder="Your Email" id="txtEmail">
</div>
</div>
<div class="row">
<div class="col form-group">
<input name="website" type="text" class="form-control" placeholder="Your Website" id="txtWebsite">
</div>
</div>
<div class="row">
<div class="col form-group">
<textarea name="comment" class="form-control" placeholder="Your Comment*" id="txtComment"></textarea>
</div>
</div>
<button type="button" class="btn btn-primary" onclick="addComment()">Post Comment</button>
</form>
</div>
<script>
function addComment() {
$.ajax({
url: "/News/AddComment" + @Model.PageID,
type: "Get",
data: { name : $("#txtName").val(), email : $("#txtEmail").val(), website : $("#txtWebsite").val(), comment : $("#txtComment").val() }
}).done(function() {
$("#txtName").val("");
$("#txtEmail").val("");
$("#txtWebsite").val("");
$("#txtComment").val("");
} );
}
</script>