The POST HTTP protocol used to access the path '/ Documents / TestNote / Documents / AddNote' is not allowed

I have two user controls on an aspx page, and one of the user controls has a text area for notes. and I'm trying to use JSON, so when they click the addnote button, it does not reload the page.

Below is my java script, but it says that it gives this error

The HTTP POST protocol used to access the path '/ Documents / TestNote / Documents / AddNote' is not allowed.

<script type="text/javascript">
    $(document).ready(function() {

        $("#btnAddNote").click(function() {
            alert("knock knock");
            var gnote = getNotes();
            //var notes = $("#txtNote").val();
            if (gnote == null) {
                alert("Note is null");
                return;

            }

            $.post("Documents/AddNote", gnote, function(data) {
                var msg = data.Msg;
                $("#resultMsg").html(msg);
            });
        });
    });

    function getNotes() {
        alert("I am in getNotes function");
        var notes = $("#txtNote").val();
        if (notes == "")
            alert("notes is empty");
        return (notes == "") ? null : { Note: notes };
    }
</script>

My controller

[HttpPost]
    public ActionResult AddNote(AdNote note)
    {
        string msg = string.Format("Note {0} added", note.Note);
        return Json(new AdNote { Note = msg });


    }
+3
source share
2 answers

in the controller use

return Json(new AdNote { Note = msg },sonRequestBehavior.AllowGet);
+1
source

:
 - var msg = data.Msg; var msg = data.Note;
 - <%=Url.Action("AddNote","Documents")%> "Documents\AddNote"

0

Source: https://habr.com/ru/post/1744213/


All Articles