user6934713 user6934713 - 1 year ago 107
AngularJS Question

http post - pass a javascript object to mvc controller

I am trying to pass a javascript object containing a string and a jstring to a mvc controller. This is my code and I am getting null value in the controller.
Thank you in advance for the help.

function setMultiQuestion(question, responses) {
qaObject = new questionAnswerObj('q', [{'correct':true,'answer':'A1'}, {'correct':true,'answer':'A2'}];);

$ + "Admin/insertMultiAnswers", { qaObject: qaObject })
.success(function (data, status, headers, config) {
.error(function (data, status, header, config) {

public ActionResult insertMultiAnswers(string[] qaObject)

Answer Source

You must send a string to server. Please use this:

$ + "Admin/insertMultiAnswers", { qaObject: JSON.stringify(qaObject) })

JSON.stringify turns a Javascript object into JSON text and stores that JSON text in a string.

View reference here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download