Angularjs Can';t从JSON格式接收Asp.Net MVC5中的对象
有一个JSON发送:Angularjs Can';t从JSON格式接收Asp.Net MVC5中的对象,angularjs,json,asp.net-mvc,Angularjs,Json,Asp.net Mvc,有一个JSON发送: var formData = new FormData(); var test = {}; test.PosX1 = 0; test.PosX2 = 10; test.PosY1 = 10; test.PosY2 = 1; test.TemplateId = 0; formData.append("block", test); ... +some file var defer = $q.defer(); $http.post
var formData = new FormData();
var test = {};
test.PosX1 = 0;
test.PosX2 = 10;
test.PosY1 = 10;
test.PosY2 = 1;
test.TemplateId = 0;
formData.append("block", test);
... +some file
var defer = $q.defer();
$http.post("/Templates/Create", formData,
{
withCredentials: true,
headers: { 'Content-Type': undefined },
//transformRequest: angular.identity
})
MVC控制器:
[HttpPost]
public JsonResult Create(string templateName, HttpPostedFileBase file, Models.ModelView.TemplateBlockView block)
{
我得到了templateName,file,但我没有得到一个block
型号:
public class TemplateBlockView
{
public int PosX1;
public int PosX2;
public int PosY1;
public int PosY2;
public int TemplateId;
}
以下是请求头:
Provisional headers are shown
Accept:application/json, text/plain, */*
Content-Type:multipart/form-data; boundary=----
我尝试了不同的内容类型,但没有结果。将
标题:{'Content-Type':undefined}
更改为`headers:{'Content-Type':application/json}`将标题:{'Content-Type':undefined}
更改为`headers:{'Content-Type':application/json}`