asp.net - Angularjs resource sending empty object to api controller -
hi have agularjs resources below working fine.
return { formdis: $resource('/api/pdisc/:id', { id: '@id' }, { update: { method: 'post' } }) };
angularjs cotroller using resource
$scope.submit = function (form) { console.log(form.dis.length); console.log(form.dis); (var = 0; < form.dis.length; i++) { prepository.formdis.update(form.dis[i], function () { { alert("saved"); } }); }; };
webconfig
config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } );
mvc api recieving
// post api/projdisc public httpresponsemessage postproject_discussion(pdis pdis) { db.project_discussion.add(pdis); db.savechanges(); }
class
[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 run error in api @
db.project_discussion.add(pdis);
error
exception of type 'system.data.entity.validation.dbentityvalidationexception' occurred in entityframework.dll not handled in user code
i error because api receiving empty object. in angular controller can see objects in console being passed form. once object submitted resource , api there wrong ends empty object. please let me know how fix it.
based on comment:
i can see right data being {"pro_id":"221","message":"sdsfsd" pdis_id:""}
my best guess model binder not able convert pdis type.
one thing notice property pdis_id int (non-nullable), , passing pdis_id:""
. think model binder not know in case.
try supplying integer value pdis_id, or not supplying @ all.
Comments
Post a Comment