asp.net mvc - How do display json data in view using Angular -
i learning angularjs , trying implement in c# web mvc application first time.
i unable json format data returned controller display in view uses angular/razor data purposes
in c# controller return json data coffe scrip/js
public actionresult load (string id){ //data retrieved model , formatted in json here return json(jsondata ,jsonrequestbehavior.allowget);
in coffee script have:
define ['test'], (app) -> ($scope, $http, $location) -> $scope.vdata = (id) -> $.ajax url: 'mobile/load?id=1237' .done (response) -> alert response $scope.vdata = [response] $scope.$apply() unless $scope.$$phase
when launch application view has alert button used test if can see data json response:
the alert shows data in following format:
{ "versions":{ "is_live":"true", "type":"multiple", "rendition":{ "@name":"my test", "@url":"http://test.net/location/test.m3u8", "@thumbnail":"http:// test.net/location/testimg/cam.png", "@thumbnail_update_interval":"10" } } }
in view have tried data in label several ways unsuccessful:
<label>{{vdata.is_live}}</label> <label>{{vdata.versions.is_live}}</label> <label>{{is_live}}</label>
while debugging in browser noticed json data in string format , not object.
could problem?
can please me display data in view json data using angular?
i'll change 2 things. first 1 if json data in string format should parse using json.parse(jsondata) when receive data on client.
i don't know coffee script i'll add missing using javascript show i'll change :
define ['test'], (app) -> ($scope, $http, $location) -> $scope.vdata = (id) -> $.ajax url: 'mobile/load?id=1237' .done (response) -> alert response $scope.vdata = json.parse( [response] ) $scope.$apply() unless $scope.$$phase
and try:
<label>{{vdata.versions.is_live}}</label>
let me know if works!
Comments
Post a Comment