ASP.NET: Page Models
Handle, route, and redirect requests using Page Models in ASP.NET
StartKey Concepts
Review core concepts you need to learn to master this subject
asp-for
URLs in Razor Pages
OnGet() & OnGetAsync()
OnPost() & OnPostAsync()
Void Handler Methods
Task Handler Methods
Handler Method Parameters
Model Binding
asp-for
asp-for
<!-- In .cshtml file -->
Enter a username: <input asp-for="Username" />
The asp-for
attribute is used to connect an <input>
element to a page model property.
The above example would be connected to a Username
property in the page model:
public class IndexModel : PageModel { [BindProperty] public string Username { get; set; } }
In the rendered HTML, attributes like type
, id
, and name
will be added to the <input>
tag:
Enter a username: <input type="text" id="Username" name="Username" >
Page Model Basics
Lesson 1 of 3
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory