Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将MVC模型数据链接到Angular JS模型_Javascript_Asp.net Mvc_Angularjs_Razor - Fatal编程技术网

Javascript 如何将MVC模型数据链接到Angular JS模型

Javascript 如何将MVC模型数据链接到Angular JS模型,javascript,asp.net-mvc,angularjs,razor,Javascript,Asp.net Mvc,Angularjs,Razor,我正在使用MVC Razor视图和AngularJS 我正在控制器中创建UserMaster对象并传递给视图 Function AddNewUser() As ActionResult Dim objUser As New UserMaster() Return View("UserMaster", objUserMaster) End Function 在视图中,通过使用HTML帮助器类,将创建文本框和验证控件 @<div ng-app ng-contro

我正在使用MVC Razor视图和AngularJS

我正在控制器中创建UserMaster对象并传递给视图

Function AddNewUser() As ActionResult
       Dim objUser As New UserMaster()
        Return View("UserMaster", objUserMaster)
End Function
在视图中,通过使用HTML帮助器类,将创建文本框和验证控件

@<div ng-app ng-controller="UserController">
    @Html.EditorFor(Function(model) model.UserName)
    @Html.ValidationMessageFor(Function(model) model.UserName)
@
@EditorFor(函数(模型)model.UserName)
@Html.ValidationMessageFor(函数(模型)model.UserName)
在客户端,使用以下语句创建AngularJS模型

    <script type="text/javascript">
           function UserController($scope, $http) {
           $scope.UserData = @Html.Raw(Json.Encode(Model));
           }
    </script>

函数UserController($scope,$http){
$scope.UserData=@Html.Raw(Json.Encode(Model));
}
服务器端验证(我在UserMaster类中编写)在客户端运行良好,razor引擎通过生成客户端验证脚本自动完成这项工作

在提交后,我会自动在服务器端获得繁荣的模型


但我无法使用AngularJS(通过使用$scope.UserData.UserName)在客户端操纵/获取模型数据。当用户使用angular JS修改时,我想访问文本框中的用户名值。。如何实现?

在MVC-5中使用htmlAttributes是可能的

@Html.EditorFor(Function(model) model.UserName, New With {Key .htmlAttributes = New With {Key .ng_model = "model.UserName"}})

我们必须使用ng_模型而不是ng模型,MVC将在运行时呈现为ng模型

你有没有弄明白这一点?是的。。。我会更新答案。。。