登录功能会出现这些错误。
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_passport
,v.mobilenumber
带下划线并显示这些错误。
错误:参数9:无法从'string'转换为'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();
}
答案 0 :(得分:2)
您没有按正确的顺序传递参数,请将您的调用修改为:
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);
如果你没有使用命名参数,那么在调用函数/方法时,你总是要小心参数的顺序
答案 1 :(得分:1)
您只能将v
变量传递给UserInfo
函数,而不是传递所有这些参数
答案 2 :(得分:0)
您的移动电话号码被声明为int
,而您正试图传递string
,请在致电UserInfo
时进行演员
UserInfo(v.user_name, v.user_fname, v.user_bloodGp, v.user_nationality, v.usertype, v.status, v.gender, v.usercnic, v.user_passport, int.Parse(v.mobilenumber));
答案 3 :(得分:0)
答案 4 :(得分:0)
其运行时错误。 string被传递给期望整数的变量,并且它试图将字符串转换为整数,从而导致无效的强制转换异常。纠正传递的参数顺序。