TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
2.1k
473.7k
UserId from the table is null when controller is called?
Jan 27 2020 12:49 PM
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));
// its null when its debugged
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);
}
}
Reply
Answers (
6
)
Pass token to API
Relationships between database tables