Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.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
Asp.net mvc 从AngularJS代码调用控制器函数(vb.net)是否正确?_Asp.net Mvc_Vb.net_Angularjs - Fatal编程技术网

Asp.net mvc 从AngularJS代码调用控制器函数(vb.net)是否正确?

Asp.net mvc 从AngularJS代码调用控制器函数(vb.net)是否正确?,asp.net-mvc,vb.net,angularjs,Asp.net Mvc,Vb.net,Angularjs,我是ASP.NET MVC新手,我不太确定是否正确调用了NewTextFile子文件。这个方法的作用是在本地服务器上创建一个文本文件。作为一个新手,我很感谢你的关注。多谢各位 function TableController($scope) { $scope.requests = []; $scope.addCertificate = function () { var certificate = { emailAddress: $sco

我是ASP.NET MVC新手,我不太确定是否正确调用了NewTextFile子文件。这个方法的作用是在本地服务器上创建一个文本文件。作为一个新手,我很感谢你的关注。多谢各位

function TableController($scope) {
    $scope.requests = [];

    $scope.addCertificate = function () {
        var certificate = {
            emailAddress: $scope.emailAddress,
            certificateType: $scope.certificateType,
            searchType: $scope.searchType,
            submittedNumbers: $scope.submittedNumbers,
        };

        $scope.requests.push(certificate);
    };

    $scope.removeCertificate = function (index) {
        $scope.requests.splice(index, 1);
    };

    $scope.requestThatCertificatesBeEmailed = function () {
        for (index = 0; index < $scope.requests.length; ++index) {
            alert('For loop entered, hello!')
            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);

            $.ajax({
                url: '/Controllers/CreateTextFile/NewTextFile',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({
                    submittedEmailAddress: submittedEmailAddressString,
                    submittedCertificateType: submittedCertificateTypeString,
                    submittedSearchType: submittedSearchTypeString,
                    submittedSearch: submittedSearchString
                }),
                processData: false,
                dataType: 'json'
            });
            alert('Succesfully submitted request')
        }
    };
}
函数表控制器($scope){
$scope.requests=[];
$scope.addCertificate=函数(){
var证书={
emailAddress:$scope.emailAddress,
certificateType:$scope.certificateType,
searchType:$scope.searchType,
SubmittedNumber:$scope.SubmittedNumber,
};
$scope.requests.push(证书);
};
$scope.removeCertificate=函数(索引){
$scope.requests.splice(索引1);
};
$scope.requestThatCertificatesBeEmailed=函数(){
对于(索引=0;索引<$scope.requests.length;++index){
警报('对于输入的循环,您好!')
var submittedEmailAddressString=$scope.requests[index].emailAddress;
var submittedCertificateTypeString=$scope.requests[index].certificateType;
var submittedSearchTypeString=$scope.requests[index].searchType;
var submittedSearchString=$scope.requests[index]。submittedNumber;
警报(submittedSearchTypeString);
$.ajax({
url:“/Controllers/CreateTextFile/NewTextFile”,
键入:“POST”,
contentType:'应用程序/json',
数据:JSON.stringify({
SubmittedMailAddress:SubmittedMailAddressString,
submittedCertificateType:submittedCertificateTypeString,
submittedSearchType:submittedSearchTypeString,
submittedSearch:submittedSearchString
}),
processData:false,
数据类型:“json”
});
警报(“已成功提交请求”)
}
};
}
下面是我的vb.net控制器类:

Imports System.Threading.Tasks
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin.Security

Public Class CreateTextFileController

    Inherits System.Web.Mvc.Controller

    <HttpPost> _
    <NonAction()> _
    Private Sub NewTextFile(submittedEmailAddress As String, submittedCertificateType As String, submittedSearchType As String, submittedSearch As String)

    //Create Textfile on local server here given the input parameters

    End Sub

End Class
导入System.Threading.Tasks
导入Microsoft.AspNet.Identity
导入Microsoft.AspNet.Identity.EntityFramework
导入Microsoft.AspNet.Identity.Owin
导入Microsoft.Owin.Security
公共类CreateTextFileController
继承System.Web.Mvc.Controller
_
_
私有子NewTextFile(SubmittedMailAddress作为字符串,submittedCertificateType作为字符串,submittedSearchType作为字符串,submittedSearch作为字符串)
//根据输入参数在本地服务器上创建文本文件
端接头
末级

我认为,从您在angularjs文件中调用的url判断,您缺少的关键要素是“路由”。以下是一些有用的链接:

简而言之,“路由”是MVC用来描述“将url与控制器方法关联”的术语。您的角度文件具有以下功能:


$.ajax({
url:“/Controllers/CreateTextFile/NewTextFile”,
...

因为路由将url从文件路径中抽象出来,所以不会执行您想要的操作。相反,您将使用文件路径和方法名称作为url,这不一定会发生。路由功能非常强大,您可以将多个url映射到一个方法,或者一个方法映射到具有各种模式的多个url诀窍是,你会想没有它你会做什么


另外,您应该注意下面的评论:使用
$http
angular模块在JQuery中执行ajax请求,因为它更好地与angularjs框架集成。

不要将JQuery的ajax与angular结合使用,在URL中使用
$http
,不要使用控制器前缀。只使用控制器和动作,这是正确的w您的路由已配置(您可以在浏览器中使用控制器/操作点击它)(默认)。我对所有这些都不熟悉,所以我不知道我在做什么,但我的CreateTextFileController类位于名为“控制器”的文件夹中。然后我要调用的方法是NewTextFile。我感谢您的输入!