Dies ist eine Aktion zum Posten eines Kommentars. Aus irgendeinem Grund wird der Kommentar zweimal gepostet. Wenn ich einen Haltepunkt setze, sehe ich, wenn es auf den Grund dieser Aktion kommt, geht es wieder an den Anfang zurück! Ich kann nicht herausfinden, warum?Warum läuft diese Aktion zweimal?
[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 });
}
ist die Javascript
$(".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;
});
});
});
Hier wird die Ansicht
<button type="button" data-workerid="@Model.Cleaner.id" data-userid="@Model.User.id" class="btn btn-default postComment" data-dismiss="modal">Post Comment</button>
Es wird wahrscheinlich etwas in Ihrem View sein. – itsme86
Ich denke, das Problem liegt in der Ansicht oder in einem Skript. – Jhonathan
Benutzer Kommentare zu? Dies kann auf eine clientseitige Ereignisduplikation zurückzuführen sein. –
dlatikay