I’m trying to get a json string back from my controller, that is prefill-values for a jqGrid column.
$("#dagbok_grid").setColProp("Kalla", { editoptions: { value:
$.getJSON('@Url.Action("GetKalla", "Dagbok")', { }, function (data) {
alert("sdf");
//What to do here, to get the json string here?
});
} });
I have two problems, I suspect that they are connected. I’m getting a syntax error in the javascript above. Also, How do I output the data that is returned from the controller action?
AJAX is asynchronous. That’s what the first A in the acronym stands for. The
$.getJSONmethod doesn’t return what you think. This method triggers an AJAX request and returns immediately. The result of this request will be available much later in the success callback. So you cannot simply assign thevalueproperty to$.getJSONas you did.You should first send an AJAX request and then invoke the
setColPropmethod inside the success callback: