从数据库中获取单词 - 不会有任何内容

时间:2016-07-14 15:55:02

标签: javascript c# angularjs

这就是我试图这样做以便它检索我在数据库中的内容。我得到的内容不是通过C#来实现的,但是我想这样做,以便在写作时立即找到单词" L"然后所有的话语都以L为主。

现在不是内容了。但是我快速重新加载页面给了我{{VALUE}}存在的一种符号,但没有得到任何结果。

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;
    });
});

资料:

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

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

        return View(model);
    }

我在这里寻找:

  1. Her
  2. Http-Get
  3. EIDT - 更新:

    [HttpGet]
        public JsonResult MWordSpreads()
        {
            WordsSpreadsListValue model = new WordsSpreadsListValue();
    
            var db = HelperToTables.DbValue;
            var _modelList = db.WordSpreads.ToList();
    
            return Json(_modelList, JsonRequestBehavior.AllowGet);
        }
    

2 个答案:

答案 0 :(得分:0)

../Profile/MWordSpreads中,它会将html文档作为数据返回并设置为$scope.entries。这就是为什么你不能在页面中显示数据的原因。

我建议改用ApiController。

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

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

        return model;
     }

很长时间没有使用angularjs,我不确定下面的代码是否有效。

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

Words.cshtml:你可以像WordSpreads

获得类{{Value.someprop}}的属性

答案 1 :(得分:0)

我只测试了客户端部分(Javascript)并且它有效:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Search</title>
</head>
<body>
    <div class="container" style="min-height:300px;" ng-app="WordSpreads" ng-controller="WordSpreadsListValue">
    <div class="col-md-12">
    <input type="text" class="form-control input-lg" ng-model="test">
    <div ng-repeat="Value in entries | filter:test"> 
        {{ Value }}
    </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script>
var app = angular.module('WordSpreads', []);
app.controller('WordSpreadsListValue', function($scope, $http) {
    $scope.entries = [
        'Astrid',
        'Bjarne',
        'Casper',
        'Erik',
        'Kristin',
        'Lisbet',
        'Mikael',
        'Peter',
        'Pia',
        'Thomas'
    ];
});
</script>
</body>
</html>

这对你有帮助吗?

...

啊!更愿意使用

$http.get('../Profile/MWordSpreads')
.then(function(response) {
    $scope.entries = response.data.entries;
}, function(rejection) {
    alert('Error: ' + JSON.stringify(rejection, null, 4));
});

而不是

$http.get('../Profile/MWordSpreads')
.success(function(data, status, headers, config) {
    $scope.entries = data.entries;
})
.error(function(data, status, headers, config) {
    alert('Error: ' + status +  ' ' + JSON.stringify(data, null, 4));
});