I am trying to submit some values from a form to my mvc controller.
Here is my controller:
//Post/ Roles/AddUser
[HttpPost]
public ActionResult AddUser(String json)
{
Log.submit(json);
return View();
}
here is the js:
<script>
function submitForm() {
var usersRoles = new Array;
$("#dualSelectRoles2 option").each(function () {
usersRoles.push($(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);
}
});
}
When I debug on the controller I get my parameter to be null?
The console.log(usersRoles)
gives me data.
What am I doing incorrectly?
How can I receive a json object in the controller?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…