Reputation: 417
i just started with the basics of AngularJS and tried to show UserName via ng-bind method in a modal popup, but i'm not able to display UserName in the output from my MVC View. My Angularjs code is here
<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>
My problem is when i click on Preview button, it will show popup but there it won't display Username. Can anyone please tell me how to show Username in popup. Thanks
Upvotes: 0
Views: 815
Reputation: 1634
Your ng_init should be assigning UserName like below
@Html.Hidden("Name", UserName, new { ng_init = "UserName='"+ UserName + "'" });
and ng-bind as below
<p ng-bind="UserName"></p>
Upvotes: 1