我刚刚开始使用AngularJS的基础知识,并尝试在模式弹出窗口中通过ng-bind方法显示UserName,但我无法在MVC视图的输出中显示UserName。我的Angularjs代码在这里
<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>
我的问题是,当我点击预览按钮时,它会显示弹出窗口,但不会显示用户名。任何人都可以告诉我如何在弹出窗口中显示用户名。感谢
答案 0 :(得分:1)
你的ng_init应该像下面那样分配UserName
@Html.Hidden("Name", UserName, new { ng_init = "UserName='"+ UserName + "'" });
和ng-bind如下
<p ng-bind="UserName"></p>