我想傳遞一個包含通行證JavaScript對象與HTTP POST
question(string), multianswers(answer(string),correct(bit)).
這是一個JavaScript對象multianswers的價值 -
[{'correct':true,'answer':'A1'}, {'correct':true,'answer':'A2'}];
什麼類型應該是我傳遞的參數到控制器。
function setMultiQuestion(question, responses) {
var responsesList = angular.toJson(responses);
function questionAnswerObj(question, answers)
{
this.question = question;
this.answers = answers;
}
qaObject = new questionAnswerObj(question, responsesList);
$http.post(baseUrl + "Admin/insertMultiAnswers", { data: qaObject })
.success(function (data, status, headers, config) {
$mdDialog.hide();
$mdToast.show(
$mdToast.simple()
.textContent('New question was added.')
.position('top')
.hideDelay(5000)
.theme('success-toast')
);
})
.error(function (data, status, header, config) {
});
}
而這是我的控制器。
[HttpPost]
public ActionResult insertMultiAnswers(object data)
{
try
{
Console.Write(data);
// data.setMultiAnswer();
Response.StatusCode = 200;
return Content("Sucess");
}
catch (Exception ex)
{
Response.StatusCode = 500;
return Content("Fail");
}
}
你使用任何類相同? – Aravind