Asp.net 如何从angularJS代码调用vb.net函数?

Asp.net 如何从angularJS代码调用vb.net函数?,asp.net,vb.net,angularjs,Asp.net,Vb.net,Angularjs,我试图将存储在动态创建的表中的数据传递给服务器,虽然我可以访问angularJS控制器中的数据,但我很难学习如何将这些数据传递给服务器进行处理 这是我的angularjs函数,它可以访问我的表数据,它只是传递数据并调用我遇到问题的vb.net函数 $scope.requestThatCertificatesBeEmailed = function () { for (index = 0; index < $scope.requests.length; ++index) {

我试图将存储在动态创建的表中的数据传递给服务器,虽然我可以访问angularJS控制器中的数据,但我很难学习如何将这些数据传递给服务器进行处理

这是我的angularjs函数,它可以访问我的表数据,它只是传递数据并调用我遇到问题的vb.net函数

$scope.requestThatCertificatesBeEmailed = function () {
    for (index = 0; index < $scope.requests.length; ++index) {
        alert('For loop entered')
        var submittedEmailAddressString = $scope.requests[index].emailAddress;
        var submittedCertificateTypeString = $scope.requests[index].certificateType;
        var submittedSearchTypeString = $scope.requests[index].searchType;
        var submittedSearchString = $scope.requests[index].submittedNumbers;

        alert(submittedSearchTypeString);

        $http.post("/Home/NewTextFile", { submittedEmailAddress: submittedEmailAddressString, submittedCertificateType: submittedCertificateTypeString, submittedSearchType: submittedSearchTypeString, submittedSearch: submittedSearchString }).error(function () {
            $scope.requests = [];
        });

您需要将数据发布/放回服务器。如果您在ASP.NET WebForms应用程序中工作,则可能需要在隐藏的输入字段中将值作为JSON传递给服务器。如果您在ASP.NET MVC应用程序中工作,则应该能够调用控制器操作,从javascript发送JSON表数据

MVC控制器中的操作方法应如下所示:

<HttpPost> _
Public Function NewTextFile(submittedEmailAddress As String, submittedCertificateType As String, submittedSearchType As String, submittedSearch As String) As ActionResult
    'do some work
End Function
下面是我快速组合的AngularJS示例:

在视图上/从视图中引用:

<script type="text/javascript">
    angular.module('httpExample', [])
            .controller('ContactController', ['$scope', '$http',
                function ($scope, $http, $templateCache) {
                    $scope.contact = { userName: '', firstName: '', lastName: '' };

                    $scope.get = function () {
                        $scope.code = null;
                        $scope.response = null;

                        $http.get('/Home/Contact').
                        success(function (data, status) {
                            $scope.status = status;
                            $scope.data = data;
                            $scope.contact = data;
                        }).
                        error(function (data, status) {
                            $scope.data = data || "Request failed";
                            $scope.contact = { userName: '', firstName: '', lastName: '' }
                            $scope.status = status;
                        });
                    };

                    $scope.post = function () {
                        $scope.code = null;
                        $scope.response = null;

                        $http.post('/Home/Contact', $scope.contact).
                        success(function (data, status) {
                            $scope.status = status;
                            $scope.data = data;
                        }).
                        error(function (data, status) {
                            $scope.data = data || "Request failed";
                            $scope.status = status;
                        });

                    };

                }]);
</script>
在身体的某个地方:

<div>
    <div ng-app="httpExample">
        <div ng-controller="ContactController">
            <fieldset>
                <legend>Contact</legend>
                Username: <input type="text" ng-model="contact.userName"/><br/>
                Last Name: <input type="text" ng-model="contact.lastName"/><br/>
                First Name: <input type="text" ng-model="contact.firstName"/><br/>
            </fieldset>
            <br />
            <button id="getbtn" ng-click="get()">get</button>
            <button id="postbtn" ng-click="post()">post</button><br/><br/>

            <pre>http status code: {{status}}</pre>
            <pre>http response data: {{data}}</pre>
        </div>
    </div>
</div>
MVC服务器端主控制器的方法如下所示:

<HttpPost> _
Public Function NewTextFile(submittedEmailAddress As String, submittedCertificateType As String, submittedSearchType As String, submittedSearch As String) As ActionResult
    'do some work
End Function

非常感谢。我确实在使用ASP.NETMVC应用程序。我会开始研究你包含的关键词。我在问题帖子中编辑了angularJS函数。您可以看到我试图调用vb.net函数的微弱尝试,但不幸的是,它没有被调用。请回复更多详细信息。谢谢,谢谢你。这确实让我朝着正确的方向前进。对于这个项目,我使用AngularJS而不是Jquery。如果不是太难,你能把你的代码翻译成AngularJS吗?不管怎样,非常感谢。@BryanTorres我认为上面的角度例子应该能帮助你
<HttpGet> _
Public Function Contact() As JsonResult
    Dim contact = New With { .userName = "smithjk", .firstName = "John", .lastName = "Smith" }
    Return Json(contact, JsonRequestBehavior.AllowGet)
End Function

<HttpPost> _
Public Function Contact(userName As String, firstName As String, lastName As String) As ActionResult
    'do some work
    System.Diagnostics.Debug.Print(userName)
    Return New EmptyResult()
End Function