Friday, 15 April 2011

c# - TypeError: Cannot assign to read only property 'method' of VAR -



c# - TypeError: Cannot assign to read only property 'method' of VAR -

i using angularjs post webapi (c#/.net). working removed password field userprofile object (because i'm using entity framework , don't want have column in table) , passing password string interface userscontroller via posting.

problem: userscontroller never receives post because browser throws error:

typeerror: cannot assign read property 'method' of password

here angularjs code doing post userscontroller:

var _adduser = function(newuser, password) { var deferred = $q.defer(); alert('_adduser password ' + password); **//********** password gets here fine** $http.post("/api/v1/users", newuser, password) **// <-- breaks** .then(function(result) { //success var newlycreateduser; angular.copy(result.data, newlycreateduser); _users.splice(0, 0, newlycreateduser); deferred.resolve(newlycreateduser); }, function () { //error deferred.reject(); }); homecoming deferred.promise(); }

here userscontroller method supposed send stuff to:

public httpresponsemessage post([frombody]userprofile newuser, string password) { if (newuser.created == default(datetime)) { newuser.created = datetime.utcnow; } if (_repo.adduser(newuser, password) && _repo.save()) { homecoming request.createresponse(httpstatuscode.created , newuser); } else homecoming request.createresponse(httpstatuscode.badrequest); }

i decided not collect password in separate string , tell entity framework ignore password class [notmapped] decoration.

c# asp.net-mvc angularjs computer-science

No comments:

Post a Comment