so from website.com/Admin I need to display a form that gets the key from the user, after the key=="my password" it displays a button that redirects to the table view page, this page should only display something only if the key was equal to my password
ControllerAdminPage
public IActionResult Login()
{
AdminModel keyModel = new AdminModel();
keyModel.key = Request.Form["key"];
ViewData["AdminModel"] = keyModel;
return View("Admin", keyModel);
}
How can I access that specific keyModel.key from another controller ?
ControllerOfTablePage
public async Task<IActionResult> Index()
{
return View(await _context.Links.ToListAsync());
}
I've tried to do something like this in .cshtml pages:
ReadTableView
@using WebPage.Models
@model IEnumerable<WebPage.Models.LinkModel>
@{
ViewData["Title"] = "Index";
var admin = ViewData["AdminModel"] as AdminModel;
}
@if (admin?.key == "pwd") //logic of Read Table
AdminPageView(WhereTheFormOfKeyIs)
@using WebPage.Models
@{
ViewData["Title"] = "Admin";
var admin = ViewData["AdminModel"] as AdminModel;
}
@if (admin?.key == "pwd")
{
LOGGED IN SUCCESFULLY
<form method="post" asp-action="ViewLinks">
<input type="submit" value="Links Table"/>
</form>
</div>
}
else
{
<div id="login_form">
<form method="post" asp-action="Login">
Key:
<input type="text" name="key" />
<input type="submit" value="Log in" />
</form>
</div>
</body>
}