用户未定义Angular js [英] User is not defined Angular js

查看:94
本文介绍了用户未定义Angular js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在单击按钮时遇到问题,它给我一个错误,提示用户未定义 我不知道是什么问题

i have a problem when i click in the button it give me an error that user is not defined i don't know what the problem

<input type="button" class="btn btn-danger" value="Active"
       ng-click="Active(User)" />

这是我在Controller Asp MVC页面中的功能:

this is my function in page Controller Asp MVC :

public string Active(AspNetUser User)
    {
        if (User == null) return "User Not Updated! Try Again";
        var userToUpdate = db.AspNetUsers.Where(x => x.Id == User.Id).FirstOrDefault();        
        if (userToUpdate == null) return "User Not Found.";
        if (userToUpdate.IsActive == true)
        {
            userToUpdate.IsActive = false;
    }
        else
        {
            if (userToUpdate.IsActive == false)
            {
                userToUpdate.IsActive = true;
            }
            db.SaveChanges();
            return "User successfully Changed";
        }
        return "User already changed";
    }

这是我的脚本:

$scope.Active = function() {  
    $http({
        method: "post",  
        url: "http://localhost:61484/AspNetUsers/Active",  
        datatype: "json",  
        data: JSON.stringify(User)  
    }).then(function(response) {  
        alert(response.data);  
        $scope.GetAllData();  
    })  
};  

推荐答案

您没有将任何内容传递给函数$scope.Active.通过User:

You are not passing anything to the function $scope.Active. Pass the User:

$scope.Active = function(User) {...}

这篇关于用户未定义Angular js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆