JQUERY ajax passing value from MVC View to Controller

后端 未结 6 1095
再見小時候
再見小時候 2020-11-27 16:41

What I want is to pass the value of txtComments from View (using jquery/ajax) to Controller.

The problem is the ajax/jquery doesn\'t accept script tags as string. M

6条回答
  •  余生分开走
    2020-11-27 17:17

    $('#btnSaveComments').click(function () {
        var comments = $('#txtComments').val();
        var selectedId = $('#hdnSelectedId').val();
    
        $.ajax({
            url: '<%: Url.Action("SaveComments")%>',
            data: { 'id' : selectedId, 'comments' : comments },
            type: "post",
            cache: false,
            success: function (savingStatu`enter code here`s) {
                $("#hdnOrigComments").val($('#txtComments').val());
                $('#lblCommentsNotification').text(savingStatus);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                $('#lblCommentsNotification').text("Error encountered while saving the comments.");
            }
        });
    });
    

提交回复
热议问题