0

I'm trying to access my asp.net MVC model from angularjs. I can convert the model to a javascript object using var model = @Html.Raw(Json.Encode(Model)); this works fine -I can access the object from the console in chrome.

Next I try to create a UL wit ng-repeat -this doesn't work. The UL does not appear on the page and there are no errors in the console. Can anyone tell me what I might be doing wrong?

<script type="text/javascript" src="/Scripts/angular.min.js"> </script>
<script type="text/javascript" src="/Scripts/app.js"> </script>




<h2>Heading</h2>


    @using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal" ng-app="app" ng-controller="editUser">

        <script type="text/javascript">
            var model = @Html.Raw(Json.Encode(Model));
            var Permissions = model.Permissions;
        </script>

        <h4>UserSetting</h4>
        <hr/>
        @Html.ValidationSummary(true, "", new {@class = "text-danger"})
        @Html.HiddenFor(model => model.Id)



        <ul>
            <li ng-repeat="permission in Permissions">
                <span>{{permission.Guid}}</span>
                <p>{{permission.SatelliteAccount}}</p>
            </li>
        </ul>

And my app.js:

var app= angular.module('app', []);

app.controller('editUser', function ($scope) {



});

1 Answer 1

1

ng-repeat is repeating over $scope.Permissions, which is undefined. You cannot repeat over global variables, you need to define those on the angular scope in the controller.

app.js:

var app= angular.module('app', []);

app.controller('editUser', function ($scope) {

    $scope.Permissions = Permissions;

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.