Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having my login model.


C#
public class Login
   {

       [Required]
       [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
       [DataType(DataType.Password)]
       [Display(Name = "Password")]
       public string password { get; set; }

       [Required(ErrorMessage = "Enter User name")]
       public string username { get; set; }
   }





when i am geting value from view to controler in thisway


C#
Login t = new Login();

           t.password = fr["password"];
           t.username = fr["username"];



but error is coming...
C#
password The name 'password' does not exist in the current context


C#
username The name 'password' does not exist in the current context


What I have tried:

C#
public ActionResult Login(FormCollection fr)
        {
            //if (ModelState.IsValid)
            Login t = new Login();
       
            t.password = fr["password"];
            t.username = fr["username"];


               
                bool success = objIAccountData.Login(t);
                //var UserID = GetUserID_By_UserName(login.username);
                //var LoginType = GetRoleBy_UserID(Convert.ToString(UserID));

                if (success == true)
                {
                    if (string.IsNullOrEmpty(Convert.ToString(LoginType)))
                    {
                        ModelState.AddModelError("Error", "Rights to User are not Provide Contact to Admin");
                        return View(login);
                    }
                    else
                    {
                        Session["Name"] = login.username;
                        Session["UserID"] = UserID;
                        Session["LoginType"] = LoginType;

                        if (Roles.IsUserInRole(login.username, "Admin"))
                        {
                            return RedirectToAction("AdminDashboard", "Dashboard");
                        }




                        else
                        {
                            return RedirectToAction("UserDashboard", "Dashboard");
                        }
                    }
                }
                else
                {

                    ModelState.AddModelError("Error", "Please enter valid Username and Password");
                    return View(login);
                }
            
            //else
            //{
            //    ModelState.AddModelError("Error", "Please enter Username and Password");
            //}
            return View(login);

        } 
Posted
Updated 23-Jul-16 0:25am
v2

1 solution

Can you share your view as well ? Your model and controller appears to be fine. Add a watch on fr (your formcollection) to see if username and password are actually present there.
 
Share this answer
 
v2
Comments
Member 10874581 26-Jul-16 2:27am    
ok i send to you login view.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900