我如何...如何在AngularJS客户端S中获取MVC模型数据 [英] How do I...How to get MVC Model data in AngularJS client S

查看:115
本文介绍了我如何...如何在AngularJS客户端S中获取MVC模型数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVC Razor View和AngularJS。



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



I am using MVC Razor View with AngularJS.

I am creating the UserMaster object in controller and passing to the view

Function AddNewUser() As ActionResult
       Dim objUser As New UserMaster()
        Return View("UserMaster", objUserMaster)
End Function





在视图中,通过使用HTML帮助程序类,将创建文本框和验证控件



In View, By using HTML helper classes the text box and validation controls will be created

@<div ng-app ng-controller="UserController">
    @Html.EditorFor(Function(model) model.UserName)
    @Html.ValidationMessageFor(Function(model) model.UserName)



在客户端使用以下语句创建AngularJS模型




In the client side using the following statement the AngularJS model is created

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



服务器端验证(我在UserMaster类中编写)在客户端工作正常,剃刀引擎通过生成客户端自动执行此操作边验证脚本。



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



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


The server side validations(which I have written in the UserMaster Class) are working fine in client side, The razor engine is automatically doing that by generating client side validation scripts.

I am automatically getting flourished model in server side after submit.

But I am not able to manipulate/get the model data in client side using AngularJS (by using $scope.UserData.UserName). I want to access the UserName value inside the text box when the user is modifying it by using angular JS.. How?

推荐答案

范围,


http){


scope.UserData = @ Html.Raw(Json.Encode(Model));
}
< / script>
scope.UserData = @Html.Raw(Json.Encode(Model)); } </script>



服务器端验证(我在UserMaster类中编写)在客户端工作正常,剃刀引擎通过生成客户端自动执行此操作边验证脚本。



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



但是我我无法使用AngularJS操纵/获取客户端的模型数据(使用


The server side validations(which I have written in the UserMaster Class) are working fine in client side, The razor engine is automatically doing that by generating client side validation scripts.

I am automatically getting flourished model in server side after submit.

But I am not able to manipulate/get the model data in client side using AngularJS (by using


这篇关于我如何...如何在AngularJS客户端S中获取MVC模型数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆