Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.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发送到Asp net核心_Javascript_Asp.net Core - Fatal编程技术网

将数据从Javascript发送到Asp net核心

将数据从Javascript发送到Asp net核心,javascript,asp.net-core,Javascript,Asp.net Core,我需要将数据从js发送到core 在后面我有这个模型 public class AddEmployeeVm { public EmployeeVm Employee {get; set;} publi List<PrivilegesVm> Privileges {get;set;} } 特权列表 public string UserId {get;set;} public string PrivilegeId {get;set;} public string P

我需要将数据从js发送到core

在后面我有这个模型

public class AddEmployeeVm {
     public EmployeeVm Employee {get; set;}
     publi List<PrivilegesVm> Privileges {get;set;}
}
特权列表

public string UserId {get;set;}
public string PrivilegeId {get;set;}
public string PrivilegeName {get;set;}
public bool Create {get;set;}
public bool Read {get;set;}
public bool Update {get;set;}
public bool Delete {get;set;}
因此,在我的api中,我需要接收带有文件和字段的复杂数据

我无法提供数据附加,因为无法接收特权列表, 我不能使用json解决方案,因为无法发送文件


所以请帮助我,什么javascript代码将是有效的

下面是使用AJAX发布值的
JavaScript
代码

$.ajax({
        type: 'POST',
        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
        data: { parameter1: Value1, parameter2: Value2},
        url: "/ControllerName/ActionName",
        cache: false,
        success: function (data) {
            // Process the received data.
        }
    });
在下面的
Controller
中,参数名必须与使用AJAX发布的参数名相匹配

[HttpPost]
public IActionResult ActionName(string parameter1, string parameter2)
{

}

您只需要发布包含所有相关信息的表单,并将其形状设置为与服务器上的类相匹配。在你发布之前不要试图塑造它。我没有表格,我是用Ajax发布的查看;通过这种方式,您可以轻松地通过POST发送文件。除此之外,这个问题太广泛了,试着帮助你自己,当你有具体问题时再回来。OP也希望通过POST发送文件<代码>应用程序/x-www-form-urlencoded不支持文件。
[HttpPost]
public IActionResult ActionName(string parameter1, string parameter2)
{

}