つのアクションを見つけることはできませんが。私は理由を理解できませんが、実行時にSaveNotesが見つかりません。 Application Insightは、POSTの試行を見て、404エラーを受け取ります。MVC4 APIのルーティングは、私は、次のMVC4のAPIコントローラを持っている別の
私はそれを呼び出そうとしています。私は以下のようなモーダルダイアログを持っています。 so:
<div class="modal fade" id="notesModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Notes</h4>
</div>
<div class="modal-body">
<form id="notesForm">
<input type="hidden" name="id" id="notesID"/>
<textarea id="notesTextarea" name="notes"></textarea>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" onclick="saveNotes();">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
そして、私は2つのjavascript関数を持っています。
function showNotes(id) {
$("#searchingModal").modal("show");
$.ajax("@Url.Action("Get", "API/Visitor")/" + id)
.done(function (data) {
$("#searchingModal").modal("hide");
$("#notesID").val(id);
$("#notesTextarea").val(data.Notes);
$("#notesModal").modal("show");
})
.fail(function (xhr, status, errorThrown) {
$("#searchingModal").modal("hide");
genericError(status, errorThrown);
});
}
function saveNotes() {
//alert("@Url.Action("SaveNotes", "API/Visitor")/");
$.ajax({ url: "@Url.Action("SaveNotes", "API/Visitor")/", data: $("#notesForm").serialize(), method:"POST" })
.done(function() {
$("#notesModal").modal("hide");
})
.fail(function (xhr, status, errorThrown) {
$("#notesModal").modal("hide");
genericError(status, errorThrown);
});
}
機能showNotesはうまくいきます。私はajaxリクエストを実行し、訪問者のコントローラーでGetを呼び出し、訪問者を返し、そのテキストエリアにNotesフィールドを設定し、モーダルを表示します。問題はsaveNotesです。モーダルで保存ボタンをクリックするたびに、私はdone関数の代わりに失敗関数を取得します。 errorThrownは「見つかりません」です。それでは、どのようなアクションしか見つからないのですか?私はそれに[HttpPost]
属性を入れてみました。私はIDをヌル入力可能なintにしようとしました(たとえそれがすでにルート設定でオプションですが、
)を参照してください。私はsavenotesにvoidの代わりに文字列を返すようにしました。私は$ .ajaxの代わりに$ .postを使ってみました。
はPOSTに対応するために、あなたのSaveNotesアクションを設定してみてください。私はそれがデフォルトでGETに設定されていると信じています – Ju66ernaut
@ Ju66ernaut私はSaveNotesに[HttpPost]属性を入れてみました。投稿に返信する他の方法はありますか? –
私の間違い私はあなたがコメントを投稿した後にそれを試してみた。 WebApiConfig.csに属性ルーティングを追加しましたか? – Ju66ernaut