///ffffconst res = await instancs.post( "Know/DocList_Insert", { Id: 1, Name: "酷酷酷酷酷", ClientId: 1, EqId: 1, }, { headers: { "Content-Type": "application/form-data" } } ); console.log("res:", res); };
后端
[HttpPost("DocList_Insert")]
public String DocList_Insert()
{
Debug.WriteLine("基础文档查找");
using (var ctx = new MyDbContext())
{
var knowType = new KnowType {Type="doc", Name = "2", ClientId= 1, EqId= 1 };
ctx.KnowType.Add(knowType);
ctx.SaveChanges();
return "200";//return 所有数据
}
}
修改后:
[HttpPost("DocList_Insert")]
public String DocList_Insert([FromForm] dataForm data)
{
Debug.WriteLine("基础文档查找");
using (var ctx = new MyDbContext())
{
Debug.WriteLine("插入数据:{0}",data);
var knowType = new KnowType {Type= data.Type, Name = data.Name, ClientId= data.ClientId, EqId= data.EqId };
ctx.KnowType.Add(knowType);
ctx.SaveChanges();
return "200";//return 所有数据
}
}
public class dataForm
{
public int ClientId { get; set; }
public int EqId { get; set; }
public string Name { get; set; }
public string Type { get; set; }
}
报错400原因是前端的请求头写错了
错误:{ headers: { "Content-Type": "application/form-data" } }
标签:core,Insert,data,ctx,ClientId,public,net,Type,post From: https://www.cnblogs.com/cat-cat/p/18186298