2015-10-09 72 views
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不起作用。爲什麼?

enter image description here

任何一個可以幫我想出解決辦法?

+0

角度庫是否正確地包含在頁面中? – Jai

+0

是的。請參閱上面的代碼 – himadri

+0

將您的腳本標記從局部視圖放入主頁面或執行此類操作http://geekswithblogs.net/DougLampe/archive/2010/11/12/execute-javascript-in -mvc-partial-view.aspx – Fran

回答

0

部分視圖不會觸發(角度)腳本。意思是任何使用局部視圖的角度調用/執行都不會被註冊。

該解決方案是;

使用ngInclude的樣品:

<div ng-include="showlog"></div> 
<div id="WorkArea"></div> 

也,加載角庫在頭

相關問題