I am developing website in Asp.net core 3.0 razor pages, My website which have a layout page. im storing some data like username, role name in TempData in login page model class like this
[TempData]
public int FormRoleId{ get; set; }
[TempData]
public int FormUserId { get; set; }
[TempData]
public string FormUserName { get; set; }
public IActionResult OnPost()
{
if (string.IsNullOrEmpty(eUserName.Trim()))
{
ModelState.AddModelError("UserName", "User Name is a required field.");
return Page();
}
if (string.IsNullOrEmpty(ePassword.Trim()))
{
ModelState.AddModelError("Password", "User Name is a required field.");
return Page();
}
var userresult = from usr in _context.TblAllUserDetails
where usr.UserName == eUserName.Trim() && usr.Password == ePassword.Trim() && usr.IsDeleted != true
select usr;
if (userresult != null && userresult.ToList().Count > 0)
{
int rolid = 0;
foreach (var item in userresult)
{
rolid = item.RoleId;
FormRoleId = item.RoleId;
FormUserId = item.UserId;
FormUserName = item.UserName;
FormEmailId = item.EmailId;
TempData.Keep();
}
if(rolid == 1)
{
return RedirectToPage("./Admin/Dashboard");
}
else if (rolid == 2) //Main User
{
return RedirectToPage("./Agency/Dashboard");
}
}
How to get these tempdata values in _layout pages in shared folder. im using @Model.FormUserName in _layout page, giving exception like this RuntimeBinderException: 'LEMS_Demo.Pages.Admin.DashboardModel' does not contain a definition for 'FormUserName'