私は ASP.NET MVC 4 を使用するアプリに取り組んでいます。いくつかの点で、すべてをゼロから学んでいるように感じます :)。その価値があると言われています。
コントローラーのアクションに JSON をポストする必要があります。私のアクションは次のようになります。
[Authorize]
public class MyController : Controller
{
[HttpPost]
public ActionResult RemoveItem(string itemID)
{
// Do stuff...
return Json(new { Status = 1, Message="Success" });
}
}
私の JQuery コードは次のようになります。
function removeItem(id) {
var json = { "itemID": id };
$.ajax({
type: "POST",
url: "/myController/removeItem",
contentType: "application/json; charset=utf-8",
data: json,
dataType: "json",
success: removeItemCompleted,
error: removeItemFailed
});
}
function removeItemCompleted(results) {
}
function removeItemFailed(request, status, error) {
}
Fiddler で、500 エラーが返されることに気付きました。応答の TITLE フィールドには、「無効な JSON プリミティブ: itemID」と表示されます。
私は何を間違っていますか?
ありがとうございました!