How to hide div in the view of MVC?

I am developing MVC application and using razor syntax.

In this application I am giving comment facility.

I have added a partial view, which loads the comment/Records from DB.

In below image, we can see the comment box which is called run-time for employee index view.

Now I want to remove the div when user clicks on delete button.

But its not working right now...

Please check image...

I have below code in my application...

<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>

@model  IEnumerable<CRMEntities.Comment>

  <div class="ParentBlock">



    @foreach (var item in Model)
    {
        <div class="OwnerClass" id="OwnerName" data-comment-id="@item.Id">


         <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" class="deleteComment">Delete</button></span>

          <span class="EmpName"> @Html.ActionLink("Delete", "Delete", "Comment", new { id = item.Id }, new { @style = "color:#1A6690;" })</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">
    $(document).ready(function () {
        $(".deleteComment").click(function () {
            alert("asd");
            var commentBlock = $(this).parent('.OwnerClass');
            commentBlock.hide('slow')

     });
    });



</script>

Update Script ....

$(document).ready(function () {
    $(".deleteComment").click(function () {

        var commentBlock = $(this).parent('.OwnerClass');

        $.ajax({
            type: 'post',
            url: '/Comment/DeleteComment',
            dataType: 'json',
            data:
            { 

            ////////////////////////////////////////
            //What should I write here ? How can I get comment ID here ? 
            ////////////////////////////////////////
            },
            success: function (data) {

              var commentBlock = $(this).closest('div');
            commentBlock.hide('slow');

            }

        });

 });
});

Answers


Try this:

<script type="text/javascript">
    $(document).ready(function () {
        $(".deleteComment").click(function () {
            alert("asd");
            var commentBlock = $(this).closest('div');
            commentBlock.hide('slow');
     });
    });
</script>

Also, you can use:

<script type="text/javascript">
        $(document).ready(function () {
            $(".deleteComment").click(function () {
                alert("asd");
                var commentBlock = $(this).closest('div');
                commentBlock.html('');
         });
        });
    </script>

Need Your Help

Kerberos authorization as different user

c oracle kerberos

In my programm programmed on c, i want to connect to Oracle using differen user names without using password. That's mean, that user already connected to desktop in Active Directory and already ent...

How to create a buy application prompt on a certain amount of start-up times

c# windows-phone-7 math windows-phone-8

In my trial application I am implementing a notification which asks the user whether he/she would like to buy it. I would like this message to be displayed say every other time the application in s...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.