这些错误来自登录功能。

UserInfo(v.user_name, v.user_fname, v.user_bloodGp, v.user_nationality, v.usertype, v.status, v.gender, v.usercnic, v.user_passport, v.mobilenumber);


v.user_passportv.mobilenumber下划线,并显示这些错误。


  错误:参数9:无法从“字符串”转换为“ int”
  
  错误:参数10:无法从“ int”转换为“ string”


红线显示在v.user_passport,v.mobilenumber下);两个参数。

 [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult Login(User User)
            {
                var v = db.Users.Where(modal => modal.user_name.Equals(User.user_name)).Where(modal => modal.user_passport.Equals(User.user_passport)).SingleOrDefault();


                if (v != null)
                {
                    UserInfo(v.user_name, v.user_fname, v.user_bloodGp, v.user_nationality, v.usertype, v.status, v.gender, v.usercnic, v.user_passport, v.mobilenumber);
                    return RedirectToAction("Index");

                }
                return RedirectToAction("Wrongpassword");
            }


            public ActionResult UserInfo(string user_name,string user_fname,string usercnic,string user_passport,string user_bloodGp,string user_nationality,string usertype,string status,int mobilenumber,string gender)
            {
                Session["user_name"] = user_name;
                Session["user_fname"] = user_fname;
                Session["user_cnic"] = usercnic;
                Session["user_passport"] = user_passport;
                Session["user_bloodGp"] = user_bloodGp;
                Session["user_nationality"] = user_nationality;
                Session["usertype"] = usertype;
                Session["status"] = status;
                Session["mobilenumber"] = mobilenumber;
                Session["gender"] = gender;

                return new EmptyResult();
            }

最佳答案

您没有按正确的顺序传递参数,请修改该调用:

UserInfo(v.user_name, v.user_fname, v.usercnic, v.user_passport, v.user_bloodGp, v.user_nationality, v.usertype, v.status,  v.mobilenumber, v.gender);


如果不使用命名参数,则在调用函数/方法时必须始终小心参数的顺序

关于c# - 无法从字符串转换为int?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48965360/

10-11 15:58