我在一个aspx页面上有两个用户控件,其中一个用户控件有一个用于注释的文本区。我正在尝试使用JSON,这样当他们点击addnote按钮时,它不会重新加载页面。
下面是我的java脚本,但是它显示了这个错误
不允许使用HTTP谓词POST访问路径'/Documents/TestNote/Documents/AddNote‘。
<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>我的控制器
[HttpPost]
public ActionResult AddNote(AdNote note)
{
string msg = string.Format("Note {0} added", note.Note);
return Json(new AdNote { Note = msg });
}发布于 2011-07-28 07:38:31
在控制器中使用
return Json(new AdNote { Note = msg },sonRequestBehavior.AllowGet);发布于 2010-05-06 02:47:05
我看到两个错误:
var msg = data.Msg;应该是var msg = data.Note;<%=Url.Action("AddNote","Documents")%>而不是"Documents\AddNote"https://stackoverflow.com/questions/2775649
复制相似问题