J. Willumsen J. Willumsen - 4 months ago 15
AngularJS Question

Get Words from database - There will be no content out

This is how I have tried to do so that it retrieves my content in the database. I get content rather by doing it through C # but I want to make so that it finds words instantly while writing "L" then comes all words forward with L in itself.

Now comes the not the content at all. But I reload the page quick gives me a kind of sign to {{VALUE}} exists but get nothing down.

There is no error in Colsole

Words.cshtml

<div class="container" style="min-height:300px;" ng-app="WordSpreads" ng-controller="WordSpreadsListValue">
<div class="col-md-12">
<input type="text" placeholder="@Helpers.HelperText.ContentPanel.WordText" class="form-control input-lg" ng-model="test">
<div ng-repeat="Value in entries | filter:test">
{{ Value }}
</div>
</div>




LoadWords.js:

var app = angular.module('WordSpreads', []);
app.controller('WordSpreadsListValue', function($scope, $http) {
$http.get('../Profile/MWordSpreads').success(function(data){
$scope.entries = data.entries;
});
});


Profile:

[HttpGet]
public ActionResult MWordSpreads()
{
WordsSpreadsListValue model = new WordsSpreadsListValue();

var db = HelperToTables.DbValue;
model.List = db.WordSpreads.ToList();

return View(model);
}


I look for here:


  1. Her

  2. Http-Get



EIDT - Update :

[HttpGet]
public JsonResult MWordSpreads()
{
WordsSpreadsListValue model = new WordsSpreadsListValue();

var db = HelperToTables.DbValue;
var _modelList = db.WordSpreads.ToList();

return Json(_modelList, JsonRequestBehavior.AllowGet);
}

Zen Zen
Answer

In ../Profile/MWordSpreads,it returns a html document as data and set to $scope.entries. That's why you won't get data displayed in page.

I suggest use ApiController instead.

    [HttpGet]
    public WordsSpreadsListValue MWordSpreads()
    {
        WordsSpreadsListValue model = new WordsSpreadsListValue();

        var db = HelperToTables.DbValue;
        model.List = db.WordSpreads.ToList();

        return model;
     }

Long time not use angularjs, I'm not sure if codes below works.

LoadWords.js: $scope.entries = data.List;

Words.cshtml: you could get property of class WordSpreads like this {{Value.someprop}}

Comments