私は MVC 3 アプリケーションを開発しており、かみそりの構文を使用しています。
このアプリケーションでは、コメント機能を提供しています。
ユーザーがコメントの追加ボタンをクリックすると、DB に保存され、現在の Div にも追加されます。
画像をご確認ください...
これは新しいコメントを追加する前の画像です...
この画像は、新しいコメントを追加した後のものです...
さて、私の問題は、ユーザーが新しく追加されたコメントの削除ボタンをクリックしたときです。メッセージを表示したい-「削除プロセスはここから開始します...」しかし、現在は機能しています...
これが私のコードです...
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
@model IEnumerable<CRMEntities.Comment>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
//Button which Saves currently added comment in DB as well display on screen...
<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#AddCommentButton').click(function ()
{
// alert("clicked");
$.ajax({
type: 'post',
url: '/Comment/SaveComments',
dataType: 'json',
data:
{
'comments' : $('#Comment').val(),
'EType' : @Html.Raw(Json.Encode(ViewBag.EType)),
'EId' : @Html.Raw(Json.Encode(ViewBag.EId))
},
success: function (data) {
$("p.p12").append('<div style="background-color:#FAFAFA;">Recently Added... <br /><a href="@Url.Action("Details", "Employee", new { id = "__id__" })'.replace('__id__', data.OwnerID) + '">' + data.OwnerName + '</a>'+ data.cmtDateTime +'<button type="button" id=' + data.Id + ' class="deleteComment">Delete</button></span><br />' + data.msg + '</div>')
}
});
});
});
</script>
</head>
<body>
@{
<div class="ParentBlock">
@foreach (var item in Model)
{
<div class="OwnerClass" id="OwnerName">
<span class="EmpName"> @Html.ActionLink(item.Owner.FullName, "Details", "EMployee", new { id = item.OwnerId }, new { @style = "color:#1A6690;" })</span>
@Html.DisplayFor(ModelItem => item.CommentDateTime)
<span class="EmpName"><button type="button" id = "@item.Id" class="deleteComment">Delete</button></span>
<p class="CommentP">
@Html.DisplayFor(ModelItem => item.CommentText)
</p>
</div>
}
<p class="p12">
</p>
</div>
<p id="ClassPara" class="ShowComments" onclick="chkToggle()">Show All Comments</p>
}
@Html.TextArea("Comment", "", 5, 80, "asdsd")
<input type="button" value="Add Comment" id="AddCommentButton"/>
<input type="button" value="Clear" onclick="clearText()"/>
<br />
</body>
</html>
<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
// Working code - Deletes the comment from DB and removes hide the current Div
////////////////////////////////////////////////////////
$(document).ready(function () {
$(".deleteComment").click(function ()
{
alert("Delete process start here...");
});
});
</script>