标签:move index sharp ring view str cookie 移除 turn
HttpRequest
是用户请求对象
QueryString
Form
Cookie
Session
Header
实例:
public IActionResult Index()
{
QueryString x = Request.QueryString; // ?a=1
string x = Request.Query["a"]; //1
return View();
}
HttpContext
是用户请求上下文
提供Session属性获取Session对象
Session.Set设置
Session.Remove移除
Session.TryGetValue获取数据
默认绑定方式,使用特性:
[FromBody] 请求体
[FromHeader] headers
[FromQuery] 查询字符串
[FromRoute] 路由数据
[FromForm] 表单数据
[FromServices] 服务注册
前台:
<div style="height:100px">
<input type="button" value="提交带header参数" onclick="save()" />
</div>
<script>
function save() {
$.ajax({
url: "home/index",
beforeSend: function (xhr) {
xhr.setRequestHeader("username", "tangsansan");
},
type:"post",
success: function(data) {
}
});
}
</script>
后台:
public IActionResult Index([FromHeader] string username)
{
QueryString x = Request.QueryString;
return View();
}
asp.net core MVC 控制器,接收参数,数据绑定
标签:move index sharp ring view str cookie 移除 turn
原文地址:https://www.cnblogs.com/tangge/p/10153413.html