小编ZUO*_*NGE的帖子

如何同时使用[FromBody]和[FromQuery]属性?

在post请求中,我需要同时从查询字符串中获取参数。这是我的代码,但无法工作


 [HttpPost("test")]
 public string Test(TestRequest request)
 {
      //TODO  ...
 }


    public class TestRequest
    {
        [FromHeader(Name = "id")]
        public string Id { get; set; }

        [FromQuery(Name = "traceId")]
        public string Trace { get; set; }

        public string Name { get; set; }

        [MaxLength(4)]
        public string Mark { get; set; }

        [Range(18, 35)]
        public int Age { get; set; }
    }

Run Code Online (Sandbox Code Playgroud)

.net c# asp.net .net-core asp.net-core

5
推荐指数
1
解决办法
2820
查看次数

标签 统计

.net ×1

.net-core ×1

asp.net ×1

asp.net-core ×1

c# ×1