【发布时间】:2016-11-17 10:55:59
【问题描述】:
我正在尝试传递一个包含
的 javascript 对象question(string), multianswers(answer(string),correct(bit)).
这就是多重答案的价值 -
[{'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");
}
}
【问题讨论】:
-
你是否使用任何相同的类?
标签: javascript c# angularjs model-view-controller http-post