未设置的对象引用将从数据库获取值

时间:2016-07-01 12:13:11

标签: html asp.net-mvc

当编译器为DataPass赋值时,我得到“对象引用未设置为对象的实例”运行时错误

        List<Login> Login = new List<Login>();

    public int Authentication(int UserId, string UserPass)
    {
        var result = Login.Where(r => r.Login_Id == UserId).FirstOrDefault();
        string DataPass= result.Login_Pass;//idr runtime py error ay raha hy. ky DataPass ma koi value ni hy. 
        string DataLoginType= result.Login_Type;


            if ((UserPass == DataPass) && (DataLoginType == "Admin"))
            {
                return 1;
            }
            else if ((UserPass==(result.Login_Pass)) && (result.Login_Type=="Teacher"))
            {
                return 2;
            }
        return 0;
    }

查看代码如下。

<form id="login" method="post" action="~/Authentication/Authentication">
            <div class="input-container">
                <label for="UserId">User Id</label>
                <input type="text" name="User_Id" required />
                <div class="bar"></div>
            </div>
            <div class="input-container">
                <label for="Password">Password</label>
                <input type="password" name="User_Password" required />
                <div class="bar"></div>
            </div>
            <div class="button-container">
                <input type="button"  value="Cancel" />
                <button type="submit"> Login </button>
                    @*<a href="~/Home/Index">Cancel</a>*@
            </div>

        </form>

0 个答案:

没有答案