【发布时间】:2021-08-23 22:01:09
【问题描述】:
我正在尝试将数据从我的视图发布到控制器,但计数始终为 0。我可以在开发人员控制台中看到数据作为请求的一部分传递但我的操作方法无法接收它,我我无法在这里解决问题。 开发者控制台中的数据: 来自用户界面的数据:
var massagedRawMaterials = [];
for (var i = 0; i < 5; i++) {
massagedRawMaterials.push({
name: 'Raw Material Name',
shortCode: 'Short Code',
price: 'Price'
});
}
//pass json array to controller function to save line items
$.ajax({
url: "/Home/Create",
type: "POST",
data: JSON.stringify({ rawmaterial: massagedRawMaterials }),
contentType: "application/json",
dataType: 'json',
success: function (savingStatus) {
},
error: function (xhr, ajaxOptions, thrownError) {
}
> Model C#:
public class MaterialViewModel
{
public string Name { get; set; }
public string ShortCode { get; set; }
public string Price { get; set; }
}
Controller method:
public ActionResult Create(List<MaterialViewModel> rawmaterial)
{
// some processing
}
For me the code looks okay or I am unable to find the issue here.
【问题讨论】:
-
发送请求包括以下内容 1) 客户端序列化程序数据到请求正文中(可选)2)客户端发送请求 3)服务器接收请求 4)服务器反序列化正文(可选)5)服务器处理请求 6) 服务器序列化响应主体(可选) 6) 服务器发送响应 7) 客户端接收响应 8) 客户端反序列化响应主体(可选)。你哪里失败了?通常,当您没有收到响应时,从客户端到服务器的连接会在第 2 步和第 3 步之间发生的 TLS 身份验证失败。
标签: c# jquery ajax asp.net-ajax