ASP.NET Web API POST parameter is null

前端 未结 2 1983
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 08:43

(To clarify, I have read other questions and their answers and tried all solutions, but none of them solved the issue)

I\'m debugging locally a code that I\'ll deplo

2条回答
  •  悲&欢浪女
    2021-01-13 09:13

    For what it's worth, I got sick of trying to get it to serialize correctly and did it myself.

    My data is a javascript array of strings which posts like "value=thing1,thing2,thing3" and I was able to serialize it using the following:

        $('
    ', { "id": "dynamicForm", "html": '', "action": '/api/Example/', "method": "post" }).appendTo(document.body).submit();

    Then on the server side:

    [HttpPost]
    [Route("")]
    public HttpResponseMessage Post()
    {
        var values = HttpContext.Current.Server.UrlDecode(Request.Content.ReadAsStringAsync().Result).Replace("val=","").Split(',');
    ...
    }
    

提交回复
热议问题