2017-03-22 3 views
0

의견을 게시하는 작업입니다. 어떤 이유로 코멘트가 두 번 게시됩니다. 중단 점을 넣으면이 동작의 맨 아래에 도달하면 다시 처음으로 돌아갑니다. 나는 이유를 알 수 없다? 여기 이 작업이 두 번 실행되는 이유는 무엇입니까?

[HttpPost] 
public ActionResult postComment(string comment, string userId, string workerid) 
{ 
    CleanerManager cm = new CleanerManager("Cleaning_LadyConnectionString"); 
    CommentsOnUser c = new CommentsOnUser(); 
    c.Comment = comment; 
    c.CleanerId = int.Parse(workerid); 
    c.UserId = int.Parse(userId); 
    c.Date = DateTime.Today; 
    cm.AddCommentOnUser(c); 
    return this.RedirectToAction 
     ("Profile", new { id = workerid }); 
} 

 <button type="button" data-workerid="@Model.Cleaner.id" data-userid="@Model.User.id" class="btn btn-default postComment" data-dismiss="modal">Post Comment</button> 
+1

아마 당신의보기에 뭔가있을거야. – itsme86

+0

제 생각에 문제는 View 또는 일부 스크립트에 있습니다. – Jhonathan

+0

에 의견을 게시하는 사용자입니까? 클라이언트 측 이벤트 중복으로 인한 것일 수 있습니다. – dlatikay

답변

1

다른 이벤트가 ".postComment"에 등록되고있는 버튼을 클릭 할 때마다, 그래서 라인 자바 스크립트 여기

$(".hiredButton").on('click', function() { 
    $("#commentModal").modal(); 
    $(".postComment").on('click', function() { 

     var comment = $("#Message").val(); 

     var workerId = $(".postComment").data('workerid'); 
     var userId = $(".postComment").data('userid'); 


     $.post("/S/postComment", { comment: comment, userId: userId, workerId: workerId }, function() { 
      window.location = "http://baltimoresitter.com/S/profile?Id=" + workerId; 
     }); 
    }); 

}); 

입니다

$(".postComment").on('click' ... 

마다 e run은 click 이벤트에 다른 함수를 등록하는 것이며, 두 번 이상 호출 된 것을 볼 수 있습니다.

관련 문제