Here is the code snippet from my view with temporary JavaScript code for testing:
I am trying to assign the ASP.NET MVC model (@Model
) to the AngularJS scope ($scope.person
).
Any suggestions on how to accomplish this?
Thank you,
The View
@model MyApp.Person
<script>
var myApp = angular.module('myApp', []);
myApp.controller('personController', ['$scope', '$http', function ($scope, $http) {
$scope.person = ?????
}]);
</script>
Update 1 : I attempted the following code in the JS file:
var myApp = angular.module('myApp', []);
myApp.controller('personController', ['$scope', '$http', function ($scope, $http) {
$scope.person = @Html.Raw(window.person);
}]);
In the view file:
<script>
@{
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
}
window.person = serializer.Serialize(Model);
</script>
I encountered 2 errors:
ReferenceError: serializer is not defined (on windows)
window.person = serializer.Serialize(Model);
SyntaxError: illegal character (it's the @)
$scope.person = @Html.Raw(window.person);