I'm using Web API in my project but I have a problem when I try add a picture to employee, all data register OK, only picture get an error. In other projects work fine, but using Web API I can't add this.
Error:
JsonSerializationException: Error getting value from 'ReadTimeout' on 'System.Web.HttpInputStream'.
My model:
public class EmployeeViewModel
{
public int Id { get; set; }
[Required]
[StringLength(50)]
public string Name { get; set; }
[Required]
[StringLength(50)]
public string CPF { get; set; }
[StringLength(50)]
public string City { get; set; }
[Required]
[StringLength(50)]
public string Adress { get; set; }
public int OcupationId { get; set; }
[Required]
[StringLength(100)]
public string Picture { get; set; }
public virtual Occupation Occupation { get; set; }
public HttpPostedFileBase Pic { get; set; }
}
My controller:
[HttpPost]
public ActionResult AddOrEdit(EmployeeViewModel employee)
{
if (employee.Id == 0)
{
if (employee.Pic != null)
{
var pic = Ultilidades.UploadPhoto(employee.Pic);
if (!string.IsNullOrEmpty(pic))
{
employee.Picture = string.Format("~/Content/Pictures/{0}", pic);
}
}
HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Employee",employee).Result;
TempData["SuccessMessage"] = "sucess!";
}
}