0

我没有让 Angular 工作。发生的事情是我{{ foobar }}在屏幕上看到的字面意思。

这是我的文件:

/App/Index的Index.cshtml:

@{
    Layout = null;
}

<!DOCTYPE html>
<html data-ng-app="tournament">
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">

    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    <script src="~/Scripts/angular.js"></script>
    <script src="~/Angular/app.js"></script>
    <script src="~/Angular/routes.js"></script>
</head>
<body>
    <div class="navbar">
        <div class="navbar-inner">
        <a class="brand" href="#">Title</a>
            <ul class="nav">
                <li class="active"><a href="#">Toernooien</a></li>
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
            </ul>
        </div>
    </div>

    <div data-ng-view=""></div>
</body>
</html>

应用程序.js:

var app = angular.module("tournament", []);

路线.js:

app.config(function ($routeProvider) {
    $routeProvider
      .when('/', { templateUrl: '/Home/Index', controller: 'HomeController' });
});

HomeController.js:

app.controller('HomeController', function ($scope) {
    $scope.foobar = 'barFoo';
});

/Home/Index 的 Index.cshtml

<script src="~/Angular/Controllers/HomeController.js"></script>
<div>
      Home/index
    <br />
    <input type="text" data-ng-model="foo" />
    {{ foobar }}
</div>
4

1 回答 1

0

谢谢大家帮助我。我终于弄明白了。问题出在我的 MVC 控制器中。

这是我最初的:

public ActionResult Index()
{
    return View();
}

这是解决方案:

public ActionResult Index()
{
    return PartialView();
}

现在,一切正常。

于 2013-05-20T13:14:47.223 回答