我是 .NET Core 2.0 Razor 页面的新手,我发现很难以干净的方式解决我的问题。
我创建了一个简单的登录表单,用户必须在其中输入其电子邮件和密码。我使用的模型具有电子邮件和密码的属性以及相应的数据注释。
public class AuthorizeOrganizationCommand
{
[Required(ErrorMessage ="Please fill in your email")]
public string Email { get; set; }
[Required(ErrorMessage ="Please fill in your password")]
public string Password { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的页面模型如下所示:
public class IndexModel : PageModel
{
public IndexModel()
{
}
[BindProperty]
public AuthorizeOrganizationCommand Command { get; set; }
public void OnGet()
{
}
public IActionResult OnPost()
{
if (!ModelState.IsValid)
{
return Page();
}
// Code to validate the credentials
return RedirectToPage("/Index"); …Run Code Online (Sandbox Code Playgroud)