hey guys, I'm making an asp.net web api using mvc. I have the GET/POST/PUT/DELETE all in the default controller. But what I'm testing now is the post(get is working fine), I'm using the postman extension of chrome to test this and what is happening is that postman is giving me an error due to media types any ideas how to fix this?
POST controller:
[HttpPost]
[ResponseType(typeof(Event))]
public async Task<IHttpActionResult> PostBook(Event events)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.Events.Add(events);
await db.SaveChangesAsync();
db.Entry(events).Reference(e => e.Name).Load();
var dto = new EventDto()
{
Name = events.Name,
Project = events.Project,
Objectives = events.Objectives,
City = events.City,
Country = events.Country,
EventStart = events.EventStart,
Departure = events.Departure,
Arrival = events.Arrival,
Registration = events.Registration,
NationalTransportation = events.NationalTransportation,
Accommodation = events.Accommodation,
AcNumberNights = events.AcNumberNights,
AcPreferHotel = events.AcPreferHotel,
AcPreferHotelUrl = events.AcPreferHotelUrl,
Flight = events.Flight,
FlDeparture = events.FlDeparture,
FlDepartPrefer = events.FlDepartPrefer,
FlDepartPreferUrl = events.FlDepartPreferUrl,
FlReturn = events.FlReturn,
FlRetPrefer = events.FlRetPrefer,
FlRetPreferUrl = events.FlRetPreferUrl,
Notes = events.Notes,
Files = events.Files,
Status = events.Status
};
return CreatedAtRoute("DefaultApi", new { id = events.Id }, dto);
}
JSON I'm inserting in postman:
{
"Name": "psilva",
"Project": "a",
"Objectives": "s",
"City": "a",
"Country": "s",
"EventStart": 2012,
"Departure": 2012,
"Arrival": 2012,
"Registration": "a",
"NationalTransportation": "a",
"Accommodation" : "a",
"AcNumberNights": 1,
"AcPreferHotel": "a",
"AcPreferHotelUrl": "a",
"Flight": "a",
"FlDeparture": 2012,
"FlDepartPrefer": "a",
"FlDepartPreferUrl": "a",
"FlReturn": 2012,
"FlRetPrefer": "a",
"FlRetPreferUrl": "a",
"Notes": "a",
"Files": "a",
"Status": "a"
}
error from postman:
{
"Message": "The request entity's media type 'text/plain' is not supported for this resource.",
"ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'Event' from content with media type 'text/plain'.",
"ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
"StackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)"
}
Please help