I have an ASP.NET web api built into my MVC application and it currently receives all data accompanying a request as form encoded data.
I receive this as a FormDataCollection object and parse like so:
public string Post(FormDataCollection data)
{
var first = data.Get("FirstName");
//for every supported field.
}
My response is always a JSON string.
This is fine and I want to continue to accomodate this, however I'd like my users to be able to send a JSON with content type header application/JSON as well so that I can support both.
How do I accommodate both in a simple way? Will it have to involve checking the content header and having different code to extract the attributes in each case?
public string Post(TargetModel)...The framework should parse the data it receives (form submission or JSON) in to your target model.