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 ";
}