In ASP.NET Core Views and Razor Pages we can use:
public class LoginModel
{
[BindProperty]
public bool DisplayCaptcha { get; set; }
// OR
[ViewData]
public bool DisplayCaptcha { get; set; }
// OR
[TempData]
public bool DisplayCaptcha { get; set; }
}
To share data between View/Page/Controller... But when to use each one?
In my case its a simple login page and when user set a wrong password I will display a captcha.
In the form post i'm setting a property to true (DisplayCaptcha = true) and rendering the page with the captcha:
@if (Model.DisplayCaptcha)
{
<div class="captcha-header">
...
</div>
}
This is working fine but i'm little confuse what type the attribute should be or even if I should use any.