1

These error are coming in the Login function.

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 is underlined and these errors are showing.

Error: Argument 9: Cannot convert from 'string' to 'int

Error: Argument 10:Cannot convert from 'int' to 'string'

Red Lines are shown under v.user_passport, v.mobilenumber); two parameters.

 [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();
            }
  • Just a piece of friendly advice: * Why does the UserInfo method return ActionResult when the returned value is never used? (Why it doesn't return void?) * Why does the method take a lengthy list of parameters instead of the User object itself? * A phone number is logically a string, not a number. ('604' and '0604' are different numbers.) * Finally (but most importantly), don't store passwords in plaintext in the database! Use appropriate hashing and salting instead. – Mike Rosoft Feb 25 '18 at 17:22
  • Thanks for the suggestions.I have already noticed that and did some change. –  Feb 25 '18 at 17:46

4 Answers4

2

You are not passing the parameters in the right order, modify your call to that:

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);

If you are not using named parameters, you have always to be careful about the order of the parameters when you are calling a function/method

AMINCHAR
  • 225
  • 1
  • 11
1

You can pass only the v variable to your UserInfo function instead of passing all those parameters

simoha
  • 35
  • 6
0

Your mobilenumber is declared as int, and you are trying to pass a string, please do a cast when calling the 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));
AMINCHAR
  • 225
  • 1
  • 11
  • By the way, maybe you should change the datatype of the mobilenumber to be string, because sometimes users can add "+" in front of the phone number (using the international format of phone numbers: +34...) – AMINCHAR Feb 24 '18 at 17:14
  • Yes but I have used int mobilenumber is User class model and you can see in the parameter I am passing an integer. I still can't get it. –  Feb 24 '18 at 17:17
  • Are you sure that your mobilenumber in Class user model is an Int? Can you post the User class model? – AMINCHAR Feb 24 '18 at 17:19
  • public class User { public int userid { get; set; } [Required] public string user_name { get; set; } [Required] public string user_fname { get; set; } public string usercnic { get; set; } public string user_passport { get; set; } public string user_bloodGp { get; set; } public string user_nationality { get; set; } public string usertype { get; set; } public string status { get; set; } public int mobilenumber { get; set; } public string gender { get; set; } } –  Feb 24 '18 at 18:00
  • I added a new answer to your question, please check it – AMINCHAR Feb 24 '18 at 18:17
0

Its run-time error. string is passed to variable where integer is expected and and its trying to cast string to integer causing Invalid cast exception. correct the order of parameters being passed.

user9405863
  • 1,506
  • 1
  • 11
  • 16