1

I'm using .net mvc3 application with angular js. In my view i'm trying to create the input field with ng-model property. Suppose if i have the following code, how i have to add ng-model attribute?

@foreach(var item in Model.ListItem)
{
   <input type="text" value="item.name" name="Model.ListItem[count].name" ng-model="???"/>
} 

Please help me with this.

0

1 Answer 1

2

I don't like the idea of meshing with backend template, but this should work:

<script>
    angular.module("YourApp", [])
    .controller("YourController", function($scope) {
        $scope.list = [];

        @foreach(var item in Model.ListItem)
        {
            $scope.list.push({
                name: "@item.name"
                // add other properties if you like
            });
        }
    });
</script>

<div ng-app="YourApp">
    <div ng-controller="YourController">
        <input ng-repeat="item in list" type="text" name="{{item.name}}" ng-model="item"/>
    </div>
</div>
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.