Ad

Move Data View To Javascript Without Click Button

I have a view and there is a button in this page. When I click that button I can get a parameter (@say_note.ID). But I want to get this parameter in javascript without click button.

My View :


                    @foreach (Note say_note in Model)
                    {
                        <div class="col-lg-12" data-note-id="@say_note.ID">

                            <div class="card h-100">

                                <div class="card-body">
                                    <h4 class="card-title">
                                        <a target="_blank" rel="nofollow noreferrer" href="/Home/ByNote/@say_note.ID">
                                            @say_note.Tittle
                                        </a>
                                    </h4>

                                    <h6 class="text-right">
                                        <h7>@say_note.Owner.Username</h7><i class="fas fa-user"></i><br />
                                        <h7> @say_note.ModifiedOn.ToString("dd.MM.yyyy")</h7><i class="far fa-clock"></i>
                                    </h6>

                                    <p class="card-text">
                                        @say_note.Text
                                    </p>

                                </div>
                                <div class="card-footer">
                                    <p>
                                        <button data-toggle="collapse" data-target="#collapse_CommentPopup" data-note-id="@say_note.ID" class="btn btn-sm btn-outline-secondary float-md-right">
                                            <i class="fas fa-comment-alt"></i> Yorumlar
                                        </button>

                                        <button class="btn btn-sm btn-outline-secondary float-sm-left" type="button" data-liked-button="false" data-note-id="@say_note.ID">
                                            <span class="far fa-star like-star"></span>&nbsp; <span class="like-count"> @say_note.LikeCount</span>  
                                        </button>

                                        <div class="text-right dateAndName float-sm-rigth">
                                            <a class="bottomNav" onclick="history.go(-1); return false;" target="_blank" rel="nofollow noreferrer" href="#"> Geri </a><br />
                                        </div>

                                    </p>

                                </div>

                            </div>
                        </div>                        
                    }
                </div>

My Javascript:


    $("#collapse_CommentPopup").collapse("toggle")

    $("#collapse_CommentPopup_bodyPopup").load("/Comment/ShowNoteComments/" + @say_note.ID); 
}); 

collapse_CommentPopup my collapse modal and I fill data this collapse with javascript

Ad

Answer

I solved my own question , maybe someone can use it other time

MyButton :

<button data-toggle="collapse" id="CommentButton" data-target="#collapse_CommentPopup" data-note-id="@say_note.ID" class="btn btn-sm btn-outline-secondary float-md-right">
                                            <i class="fas fa-comment-alt"></i> Yorumlar
                                        </button>

My Javascript:

$(function () {

    $("#collapse_CommentPopup").collapse("toggle")  //ModelCommentPopup isimli nesne show olduğunda (popup event'i yakaladık)

    var NoteId = $("#CommentButton").data("note-id");
   $("#collapse_CommentPopup_bodyPopup").load("/Comment/ShowNoteComments/" + NoteId); //ShowNoteComments metodunu çalıştır ve dönen partialı popup'ın bodysine yükle
});
Ad
source: stackoverflow.com
Ad