Tuesday, 6 August 2013

PostAsJsonAsync does not work when strongly type model has data annotations

PostAsJsonAsync does not work when strongly type model has data annotations

HttpClient Code:
using (HttpClient client = new HttpClient())
{
var viewModel = new DeleteListingMediaInfoViewModel()
{ Id = new Guid(id) };
RequestUri = RequestUri + "ListingMediaInfo/Delete";
//var uriArgument = new Uri(uri);
var response =
client.PostAsJsonAsync<DeleteListingMediaInfoViewModel>(RequestUri,
viewModel, CancellationToken.None).Result;
}
Above code works with:
public class DeleteListingMediaViewModel
{
public Guid ListingId { get; set; }
public Guid MediaAssetId { get; set; }
}
but not with (internal server error)
public class DeleteListingMediaViewModel
{
[Required]
public Guid ListingId { get; set; }
[Required]
public Guid MediaAssetId { get; set; }
}
any help will be appreciated

No comments:

Post a Comment