Hi team
I have procedure for Usp_UserNamebyUserId and has UserId, but on the controller for login, its state as null. How can i fix this issue? Here is my logic from the controller.
// login.cshtml
- <div class="form-group">
- <input id="BtnLogin" type="submit" class="btn btn-success btn-pressure" name="BtnLogin" value="Login" />
- <input id ="btnSubmit" type ="submit" class="btn btn-info btn-pressure" name="btnSubmit" value="Create" />
- </div>
- </div>
// controller.cs
- [HttpPost]
- [AllowAnonymous]
- [ValidateAntiForgeryToken]
- public ActionResult CreateLogin(LoginCreateModel objSubmit)
- {
- if(objSubmit.btnSubmit == "Create")
- {
- ViewBag.Message = "Details saved successfully";
- }
- return View(objSubmit);
- }
- [HttpPost]
- [AllowAnonymous]
- [ValidateAntiForgeryToken]
- public ActionResult Login(Login login)
- {
- if (ModelState.IsValid)
- {
- bool success = WebSecurity.Login(login.username, login.password, false);
- 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);
- }
- }