首页 > 其他分享 >post与.net core接受请求参数

post与.net core接受请求参数

时间:2024-05-11 13:30:07浏览次数:13  
标签:core Insert data ctx ClientId public net Type post

///ffff
  const 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" } }

正确:{ headers: { "Content-Type": "multipart/form-data" } }

 

标签:core,Insert,data,ctx,ClientId,public,net,Type,post
From: https://www.cnblogs.com/cat-cat/p/18186298

相关文章

  • .net5 动态配置
    通过自定义ConfigurationProvider可以实现从数据库获取参数,同时读取配置仍然可以使用原本的IConfiguration添加ConfigProvider处理加载配置及定期刷新配置逻辑///<summary>///配置提供者///</summary>publicclassConfigProvider:ConfigurationProvider,IDispos......
  • Python-PostgreSQL主键自动填充报错:SAWarning: Column x is marked as a member of th
    importdatetimefromsqlalchemyimportColumn,String,inspect,Integerfromsqlalchemy.ext.declarativeimportdeclarative_basefromsqlalchemy.ormimportsessionmakerfromsqlalchemyimportcreate_engineengine=create_engine(DATABASE_URL)Base=decla......
  • Core Impact 21.5 (Windows) - 高级渗透测试
    CoreImpact21.5(Windows)-高级渗透测试Fortra|CoreSecurityPenetrationtestingsoftware,ReleaseFeb2024请访问原文链接:CoreImpact21.5(Windows)-高级渗透测试,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgCoreImpact渗透测试软件,安全地发现和......
  • C#.Net筑基-运算符Family
    C#运算符内置了丰富的运算符操作类型,使用方便,极大的简化了编码,同时还支持多种运算符重载机制,让自定义的类型也能支持运算符行为。01、运算符概览运算符分类描述数学运算基础的加减乘除,及++、--赋值运算=,及各种复合赋值op=,x+=20;等效于x=x+20;比较运算比较......
  • NET6 自定义授权中间件
    AuthorizationWithCustMiddleware///<summary>///自定义授权中间件类:使用身份验证中间件存储的身份信息来进行权限验证///一定要先启用身份验证中间件(app.UseAuthentication()),它会验证请求中的身份信息,并将身份信息存储在HttpContext.User属性中///如果没有启用身份......
  • 使用.NET查询日出日落时间
    在WPF中,通过资源文件实现主题切换是个常见的功能,有不少文章介绍了如何实现手动切换主题。那如何实现自动切换主题呢?通常有两种机制:一是跟随系统明暗主题切换,二是像手机操作系统那样根据日出日落时间自动切换。本文将以终为始,采用倒推法一步步介绍如何使用.NET免费获取日出日落时......
  • Spring Cloud 部署时如何使用 Kubernetes 作为注册中心和配置中心
    一、SpringCloud支持的常见注册中心和配置中心。SpringCloud自带的注册中心Eureka以及config配置中心Nacos,支持注册中心和配置中心等,可以参考:https://www.cnblogs.com/laoqing/p/17797759.htmlZookeeperConsulEtcdKubernetes,当SpringCloud服务都是通过Kubernetes部......
  • NetSuite-Get-specific-Custom-Record-Types-and-related-sub-Custom-Fields-CarlZeng
    NetSuite:GetspecificCustomRecordTypesandrelatedsubCustomFields背景以前当使用search.create({})来获取数据时,我们需要制定特定的数据返回列;例如:search.createColumn(options)而query可以使用SELECT*FROM来动态返回所有的数据列(这在有的时候是一个优点),那么如......
  • How-to-install-NetSuite-SuiteCloud-plug-in-to-WebStorm-Updated2021-11-CarlZeng
    Install/upgradeNetSuiteSuiteCloudIDEPlug-inSuiteCloudIDEplug-inSuiteCloudIDEplug-inforWebStormisanintegrateddevelopmentenvironmentforNetSuiteplatformdevelopment.ItprovidesauserinterfaceforSuiteCloudDevelopmentFramework(SDF),......
  • 用一个查询从销售订单直通供应商账单-NetSuite
    朗读全文Yourbrowserdoesnotsupporttheaudioelement.有什么用用一个查询从销售订单直通供应商账单NetSuite:从SO销售订单,到PO采购订单,到Bill供应商账单下面文章的分享仅作为演示在SuiteQLQueryToo中的展示,现实情况下的应用可以非常灵活(由于范围广泛无法此文章中......