AspNet WebApi POST parameter is null when sending XML

前端 未结 2 847
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 08:01

I have a web api service originally using beta bits which I\'ve rebuilt using the release candidate bits and I\'m now having this problem.

I have a POST action that

2条回答
  •  情书的邮戳
    2020-12-14 08:30

    I was having the same problem as you, and found the solution by serializing the object using the XmlMediaTypeFormatter as described here: http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization#testing_object_serialization. I used the code in the "Testing Object Serialization" section at the bottom of the article, and replaced his Person object with my model.

    When I serialized my object, I noticed that the following attributes were added to the root node:

    xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://schemas.datacontract.org/2004/07/NAMESPACE.OF.YOUR.MODEL"
    

    If you add these attributes to your xml like so, your controller should correctly serialize the requestValues object:

    
      
      
      
        
          ClientName
          Client One
        
        
          ClientName
          Client Two
        
      
    
    

提交回复
热议问题