I am trying to create a controller action that accepts a custom model as a parameter.
[HttpPost]
public void SendEvent([FromForm]WebHookRequest value)
{
SiteNotification notification = Mapper.Map<SiteNotification>(value);
if (notification != null)
{
Task.Run(() => { _siteNotifier.NotifySite(notification); });
Response.StatusCode = 200;
}
else
{
// Set the status code that mailgun expects on failure
Response.StatusCode = 406;
}
}
All values in the following model class are properly deserialized, except for OriginUrl and OriginMessageId, which are assigned null in the value
parameter properties. I'm thinking that this might have something to do with the underscores in the DataMember(Name = "origin_message_id")
. I have tried changing the underscores to hyphens and the same thing happened.
[DataContract]
public class WebHookRequest
{
[DataMember(Name = "event")]
public string Event { get; set; }
[DataMember(Name = "recipient")]
public string Recipient { get; set; }
[DataMember(Name = "domain")]
public string Domain { get; set; }
[DataMember(Name = "origin_url")]
public string OriginUrl { get; set; }
[DataMember(Name = "origin_message_id")]
public string OriginMessageId { get; set; }
[DataMember(Name = "timestamp")]
public string TimeStamp { get; set; }
[DataMember(Name = "token")]
public string Token { get; set; }
[DataMember(Name = "signature")]
public string Signature { get; set; }
}
How can I get the controller to properly deserialize the x-www-form-urlencoded keys that contain underscores or hyphens?