アクションコントローラーでJSONオブジェクトを受信しようとして、午後中ずっとWebをクロールしようとしています。
それを行うための正しい、またはより簡単な方法は何ですか?
私は次のことを試しました:1:
//Post/ Roles/AddUser
[HttpPost]
public ActionResult AddUser(String model)
{
if(model != null)
{
return Json("Success");
}else
{
return Json("An Error Has occoured");
}
}
これにより、入力に null 値が返されました。
2:
//Post/ Roles/AddUser
[HttpPost]
public ActionResult AddUser(IDictionary<string, object> model)
{
if(model != null)
{
return Json("Success");
}else
{
return Json("An Error Has occoured");
}
}
投稿しようとしているjquery側で500エラーが発生しますか? (正しくバインドされていないことを意味します)。
ここに私のjQueryコードがあります:
<script>
function submitForm() {
var usersRoles = new Array;
jQuery("#dualSelectRoles2 option").each(function () {
usersRoles.push(jQuery(this).val());
});
console.log(usersRoles);
jQuery.ajax({
type: "POST",
url: "@Url.Action("AddUser")",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(usersRoles),
success: function (data) { alert(data); },
failure: function (errMsg) {
alert(errMsg);
}
});
}
やりたいことは、mvc アクションで JSON オブジェクトを受け取ることだけですか?
