1
我想使用AngularJS與ASP.Net MVC。我的問題是AngularJS不能在從@Ajax.actionLink()
調用的呈現視圖中工作。這裏是我試過的示例代碼。我有一個ASP.Net MVC控制器index()
這是如下:AngularJS無法與ASP.Net MVC部分視圖加載點擊@ Ajax.ActionLink()
public ActionResult index()
{
return View();
}
索引視圖包含了@Ajax.ActionLink
:
<div>
@Ajax.ActionLink("Show Log", "ShowLog", new AjaxOptions { UpdateTargetId = "WorkArea"})
</div>
<div id="WorkArea"></div>
<script src="~/App_Content/JS/jquery-1.7.2.min.js"></script>
<script src="~/App_Content/JS/jquery.unobtrusive-ajax.min.js"></script>
的ShowLog控制器:
public ActionResult ShowLog()
{
return View();
}
這裏的主要部分ShowLog()
查看我在哪裏添加AngularJS:
<script src="~/App_Content/JS/angular.min.js"></script>
<script src="~/App_Content/JS/Practical/Module.js"></script>
<script src="~/App_Content/JS/Practical/MainController.js"></script>
@{
Layout = null;
}
<h3>Log View</h3>
<div ng-app="AgApp">
<div ng-controller="PostController">
<div>{{MessageHeading}}</div>
</div>
</div>
當我運行索引文件時,顯示鏈接Show Log
。當我點擊它時,視圖ShowLog
已按預期在工作區中呈現,但在ShowLog
之內,AngularJS不起作用。爲什麼?
任何一個可以幫我想出解決辦法?
角度庫是否正確地包含在頁面中? – Jai
是的。請參閱上面的代碼 – himadri
將您的腳本標記從局部視圖放入主頁面或執行此類操作http://geekswithblogs.net/DougLampe/archive/2010/11/12/execute-javascript-in -mvc-partial-view.aspx – Fran