2015-09-25 42 views
0

我剛剛開始使用AngularJS的基礎知識,並嘗試在模式彈出窗口中通過ng-bind方法顯示UserName,但我無法在MVC視圖的輸出中顯示UserName。我Angularjs代碼是在這裏在ng-bind中顯示會話值

<div class="row" ng-app=""> 

//I was not knowing how to store UserName from the session into ng-init, so did like this. Not sure whether its correct. 
@{   
    //Here i am storing Username coming from session into my string variable 
    string UserName = ((Elearning.Models.tbl_Student)Session["Student"]).UserName; 

    //Here i have used mvc Hidden to use ng-init to store this UserName 
    @Html.Hidden("Name", UserName, new { ng_init = UserName }) 
} 

//Here is my button where i am going to call my popup 
<input type="button" value="Preview" class="btn btn-default" data-toggle="modal" data-target="#modalPreview" /> 

//Here is my Bootstrap popup to show ng-init value 
<div id="modalPreview" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="dtModalForget" aria-hidden="true"> 
     <div class="modal-dialog"> 
      <div class="modal-content">      
       <div class="modal-body "> 
        <p ng-bind=UserName></p>       
       </div>      
      </div> 
     </div> 
</div> 

我的問題是,當我在預覽按鈕點擊,它會顯示彈出但它不會顯示用戶名。任何人都可以告訴我如何在彈出窗口中顯示用戶名。由於

回答

1

你ng_init應該像下面

@Html.Hidden("Name", UserName, new { ng_init = "UserName='"+ UserName + "'" }); 

和NG綁定如下

<p ng-bind="UserName"></p> 
+0

大...任職分配用戶名。 – Amar