views:

115

answers:

1

I am having two user control on a aspx page and one of the user control has a text area for notes. and i am trying to use JSON so that when they click the addnote button it does not reload the page.

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

The HTTP verb POST used to access 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 });

}
A: 

I see two errors:
- var msg = data.Msg; should be var msg = data.Note;
- Use <%=Url.Action("AddNote","Documents")%> instead of "Documents\AddNote"

mmcteam.com.ua
After i made the changes u suggested it's entering the controller but not passing my dad to the controller, when i try to do Note.note, it is says "Object reference not set to an instance of an object."
Ok, debug what your action returns (for example using firebug) and share it.
mmcteam.com.ua
Also debug what `data` comes to `$.post`.
mmcteam.com.ua
I think grouping my answer and this http://stackoverflow.com/questions/2761031/asp-net-mvc-two-user-control/2761053#2761053 you can easily achieve what you want.
mmcteam.com.ua
using firebug i checked ,its getting those as when i hover over data it says object { Note: test more...}
so `data.Note` is defined, and I think you can replace `data.Msg` with `data.Note`
mmcteam.com.ua