Hi I have agularjs resources below that is working fine.
return {
formDis: $resource('/api/pDisc/:id', { id: '@id' }, { update: { method: 'POST' } })
};
angularjs cotroller using the resource is
$scope.submit = function (form) {
console.log(form.dis.length);
console.log(form.dis);
for (var i = 0; i < form.dis.length; i++) {
pRepository.formDis.update(form.dis[i], function () {
{
alert("Saved");
}
});
};
};
WebConfig is
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
MVC Api that is recieving it is
// POST api/projDisc
public HttpResponseMessage Postproject_discussion(pDis pDis)
{
db.project_discussion.Add(pDis);
db.SaveChanges();
}
Class is
[DataContract(IsReference = false)]
[Serializable]
public partial class pDis
{
public int pDis_id { get; set; }
public int pro_id { get; set; }
public string message {get; set;}
public virtual pro pro { get; set; }
public virtual people people { get; set; }
}
}
When I run it I get error in my api at
db.project_discussion.Add(pDis);
Error is
An exception of type 'System.Data.Entity.Validation.DbEntityValidationException' occurred in EntityFramework.dll but was not handled in user code
I get this error because api is receiving empty object. In angular controller I can see the objects in console being passed properly from form. Once the object is submitted to the resource and from it to api there is something wrong that it ends up as empty object. Please let me know how to fix it.