Web API form-urlencoded binding to different property names

后端 未结 2 572
半阙折子戏
半阙折子戏 2020-12-11 04:04

I am expecting a POST request with content type set to:

Content-Type: application/x-www-form-urlencoded

Request body looks like

2条回答
  •  一个人的身影
    2020-12-11 04:30

    It's an old post but maybe this could helps other people. Here is a solution with an AliasAttribute and the associated ModelBinder

    It could be used like this :

    [ModelBinder(typeof(AliasBinder))]
    public class MyModel
    {
        [Alias("state")]
        public string Status { get; set; }
    }
    

    Don't hesitate to comment my code :)

    Every Idea / comment is welcome.

提交回复
热议问题