Hi every one I am new to asp.net web API.I want to save user data in database and I am passing data using postman.
In my API controller I wrote
public HttpResponseMessage PostCustomer([FromBody] NewUser userData)
{
userData = repository.Add(userData);
var response = Request.CreateResponse<NewUser>(HttpStatusCode.Created, userData);
string uri = Url.Link("DefaultApi", new { customerID = userData.ID });
response.Headers.Location = new Uri(uri);
return response;
}
NewUser is the class as followes
public class NewUser
{
[Key]
public long ID { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public bool Status { get; set; }
public DateTime? CreatedDate { get; set; }
public DateTime? ModifiedDate { get; set; }
}
In postman I form-data I passed key and value it return's me message as follows
{"Message":"The request entity's media type 'multipart/form-data' is not supported for this resource.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type 'NewUser' from content with media type 'multipart/form-data'.","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 me to save data from postman form-data.