Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
26 views2 pages

Partial View

Uploaded by

gadala.suhasini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Partial View

Uploaded by

gadala.suhasini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Create the Login Partial View

@page
@model YourNamespace.Pages.Account.LoginModel

<div class="card">
<div class="card-header">
<h3>Login</h3>
</div>
<div class="card-body">
<form method="post">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" id="username" name="Username" class="form-
control" />
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" id="password" name="Password" class="form-
control" />
</div>
<div class="mb-3 form-check">
<input type="checkbox" id="rememberMe" name="RememberMe"
class="form-check-input" />
<label class="form-check-label" for="rememberMe">Remember
me</label>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
</div>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/
bootstrap.min.css" rel="stylesheet" />
-------------------------
@page
@model YourNamespace.Pages.Account.LoginModel
@{
ViewData["Title"] = "Login";
}

<h1>@ViewData["Title"]</h1>

<!-- Include the login partial view -->


@await Html.PartialAsync("_LoginPartial")

----------------------------------------------------------
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace YourNamespace.Pages.Account
{
public class LoginModel : PageModel
{
[BindProperty]
public string Username { get; set; }

[BindProperty]
public string Password { get; set; }

[BindProperty]
public bool RememberMe { get; set; }

public void OnGet()


{
// Optional: Add any logic for handling GET requests if needed
}

public IActionResult OnPost()


{
// Implement your login logic here (e.g., check credentials)

if (Username == "admin" && Password == "password") // Example


condition
{
// Redirect to a dashboard or home page after successful login
return RedirectToPage("/Dashboard");
}

// If login fails, return to the login page with an error message


ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return Page();
}
}
}
---------------------------------------------------------------
using System.ComponentModel.DataAnnotations;

public class LoginModel : PageModel


{
[Required]
public string Username { get; set; }

[Required]
[DataType(DataType.Password)]
public string Password { get; set; }

public bool RememberMe { get; set; }

public IActionResult OnPost()


{
if (!ModelState.IsValid)
{
return Page();
}

// Validate user credentials


if (Username == "admin" && Password == "password")
{
return RedirectToPage("/Dashboard");
}

ModelState.AddModelError(string.Empty, "Invalid login attempt.");


return Page();
}
}

You might also like