zoukankan      html  css  js  c++  java
  • asp.net core 3.x ApiController可以自动推断参数;自动验证模型状态,如果验证不通过,会自动返回400 ,前后端传参get,post

    vue get 传参:

    axios.get("http://localhost:44326/home",{params:{i:222}).then(function (res){
    console.log(res.data);
    }

    Vue post传参:

    1.拼接字符串
    var postData='name=${userName}'

    2.实例化URLSearchParams
    var postData = new URLSearchParams();
    postData.append("name",userName);
    postData.append("age",19);
    axios.post("http://localhost:44326/home",postData).then(function (res){
    console.log(res.data);
    }

    3.直接引用qs.js
    安装qs.js,
    引用qs.js,

    axios.post("http://localhost:44326/home",qs.stringify({name:"name",age:19})).then(function (res){
    console.log(res.data);
    }

    4. c# 不加apicontroller 的调用方法:
    [HttpPost]
    public string GetName(string name,int age)
    {
    return "post test";
    }

    [HttpGet]
    public string GetName(int i)
    {
    return "get test ,i ";
    }

    5. c# 加apicontroller 的调用方法:可以自动推断参数;自动验证模型状态,如果验证不通过,会自动返回400
    [HttpPost]
    [ApiController]
    public string GetName(UserInputModel userinput)
    {
    return "post test";
    }

    [HttpGet]
    public string GetName(int i)
    {
    return "get test ,i ";
    }

  • 相关阅读:
    word2010怎么把白色方框变成黑色方框?
    Ubuntu 14.04 安装 Sublime Text 3
    安装xmlspy之后,链接及邮箱等都用这个软件打开,怎样取消?
    SRAM、DRAM、SDRAM、DDR、DDR2、DDR3
    ROM和RAM区别
    shell脚本分析一
    重要网址
    vi/vim
    dump_stack使用
    BIOS、BootLoader、uboot对比
  • 原文地址:https://www.cnblogs.com/csj007523/p/13562429.html
Copyright © 2011-2022 走看看