Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# TypeError:无法分配给变量的只读属性“method”_C#_Asp.net Mvc_Angularjs_Computer Science - Fatal编程技术网

C# TypeError:无法分配给变量的只读属性“method”

C# TypeError:无法分配给变量的只读属性“method”,c#,asp.net-mvc,angularjs,computer-science,C#,Asp.net Mvc,Angularjs,Computer Science,我正在使用AngularJS发布到我的WebAPI C/.Net。它可以正常工作,但我从UserProfile对象中删除了密码字段,因为我使用的是entity framework,不想在该表中包含该列,现在通过POST将密码作为字符串从接口传递给UsersController 问题: UsersController从未收到post,因为浏览器引发错误: TypeError:无法分配给密码的只读属性“方法” 以下是我向UsersController发布的AngularJS代码: var _addU

我正在使用AngularJS发布到我的WebAPI C/.Net。它可以正常工作,但我从UserProfile对象中删除了密码字段,因为我使用的是entity framework,不想在该表中包含该列,现在通过POST将密码作为字符串从接口传递给UsersController

问题: UsersController从未收到post,因为浏览器引发错误:

TypeError:无法分配给密码的只读属性“方法”

以下是我向UsersController发布的AngularJS代码:

var _addUser = function(newUser, password) {

    var deferred = $q.defer();
    alert('_addUser password is ' + password);
    **//********** password gets here just fine**
    $http.post("/api/v1/users", newUser, password) **// <-- this is where it breaks**
        .then(function(result) {
            //success
            var newlyCreatedUser;
             angular.copy(result.data, newlyCreatedUser);
            _users.splice(0, 0, newlyCreatedUser); 
            deferred.resolve(newlyCreatedUser);
        },
        function () {
            //error
            deferred.reject();
        });

    return deferred.promise();
}

我决定不在单独的字符串中收集密码,只告诉Entity Framework忽略带有[NotMapping]装饰的password类。

这并不能回答这个问题。若要评论或要求作者澄清,请在他们的帖子下方留下评论-你可以随时在自己的帖子上发表评论,一旦你有足够的评论,你就可以了。@Shree,是的,它确实回答了这个问题。这是道格解决自己问题的办法。
public HttpResponseMessage Post([FromBody]UserProfile newUser, string password)
    {
        if (newUser.Created == default(DateTime))
        {
            newUser.Created = DateTime.UtcNow;
        }

        if (_repo.AddUser(newUser, password) 
            && _repo.Save())
        {
            return Request.CreateResponse(HttpStatusCode.Created
                , newUser);
        }

        else
        return Request.CreateResponse(HttpStatusCode.BadRequest);
    }