多个嵌套脚本包

时间:2014-07-10 10:22:49

标签: angularjs asp.net-mvc-4 razor

我在ASP.NET MVC上有angularjs应用程序。问题是Razor多次呈现@Script.Bundle() 这是实际的F12来源 <html ng-app="app"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <link href="/Assets/Bootstrap/css/bootstrap.css" rel="stylesheet"> </head> <body> <div ng-controller="mainCtrl" class="ng-scope"> <!-- ngView: --><div class="col-md-10 col-md-offset-1 tabs-view overflow ng-scope" ng- class="{reverse: reverse}" ng-view=""> <meta charset="utf-8" class="ng-scope"> <meta name="viewport" content="width=device-width" class="ng-scope"> <title class="ng-scope">Администрация</title> <link href="/Assets/Bootstrap/css/bootstrap.css" rel="stylesheet" class="ng-scope"> <div> <div>test text</div> </div> <script src="/Assets/jquery/jquery.min.js" class="ng-scope"></script> <script src="/Assets/ng/angular.min.js" class="ng-scope"></script> <script src="/Assets/ng/angular-sanitize.min.js" class="ng-scope"></script> <script src="/Assets/app/app.js" class="ng-scope"></script> </div> </div> <script src="/Assets/jquery/jquery.min.js"></script> <script src="/Assets/ng/angular.min.js"></script> <script src="/Assets/ng/angular-sanitize.min.js"></script> <script src="/Assets/app/app.js"></script> </body> </html>

这是一个ommited版本,但正如你在ng-view中看到的那样,razor再次渲染包,所以有错误说angular尝试再次加载。无法理解为什么会这样。

_Layout.cshtml (The only layout. @script bundles located here) |____ Home/Index.cshtml (nav bar wrapper with ng-view inside) |______ App/Index.cshtml (page from F12Tool) 我不知道要包括哪些内容供您考虑,询问是否需要更多信息 _Layout.cshtml的剃刀标记

<!DOCTYPE html>
<html ng-app="app">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width" />
  <title>Администрация</title>
  @Styles.Render("~/Assets/Bootstrap/css/bootstrap.css")
</head>
<body>
  @RenderBody()
</body>
@Scripts.Render("~/jquery")
@Scripts.Render("~/ng")
</html>

主页/索引的Razor标记

<div ng-controller="mainCtrl">
  </div>
<div>
    <div ng-view></div>
</div>

App / Index的Razor标记

<div><div>testig text</div></div>

MVC控制器主页

 public class HomeController : Controller
{
    // GET: Main
    public ActionResult Index()
    {
        return View();
    }
}

** MVC控制器应用程序

public class AppController: Controller {
public ActionResult Index()
    {
        return PartialView();
    }
 }

0 个答案:

没有答案