What would cause this custom XML ModelBinder to not deserialize my XML POST?

后端 未结 1 1979
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 22:39

The Model

public class SimpleUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string UserNam         


        
1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-21 23:16

    What am I missing here?

    You are missing to reset the stream before consuming it:

    var inputStream = controllerContext.HttpContext.Request.InputStream;
    inputStream.Position = 0;
    return serializer.Deserialize(inputStream);
    

    or use an XmlReader:

    using (var inputStream = controllerContext.HttpContext.Request.InputStream)
    using (var reader = XmlReader.Create(inputStream))
    {
        return serializer.Deserialize(reader);
    }
    

    0 讨论(0)
提交回复
热议问题