I am trying to get grid on view, for this I am using the jqgrid. and my action controller methods is returning me json 开发者_C百科data. I want to pick this data up in the 'var. in jquery. I am using asp.net mvc. how can i get this I tried :
$.getJSON(url:gridDataUrl,{}, function(jsonData) {
alert(jsonData);
});
);
Where gridDataUrl having my action url. how to do this?
The $.getJSON()
method signature is
jQuery.getJSON(url, [data], [callback(data, textStatus, xhr)])
...so it should look like this:
$.getJSON(gridDataUrl, function(jsonData) {
alert(jsonData);
});
Note that the first param is the URL as just a string (not a label) and that both data
and the callback are optional (denoted by []
in the signature). The above should only alert [object Object]
though, since it's the overall object...you'll need jsonData.propertyName
for example to get something meaningful out.
$.getJSON("@Url.Action("Search")", $("#jsonform").serialize(), function (data) {
$("#results").html("");
$("#phoneTemplate").tmpl(data).appendTo("#results");
});
return false;
});
I use this code along with template plugin for jquery to get json data from an action and render it on the client.
are you hiting your action with ajax call? do you construct your json with JsonRequestBehavior.AllowGet set?
return Json(yourdata ,JsonRequestBehavior.AllowGet);
精彩评论