An input model is a nested class inside a Razor Page's PageModel. It groups the values that model binding should populate from an incoming request, keeping page-specific input together. section 16.2 section 16.4
Use the pattern consistently when a page receives more than one value:
- Expose one property, commonly named Input, and decorate it with [BindProperty]. section 16.4
- Define InputModel as a nested class because its values are normally specific to one page. section 16.4
- Let ASP.NET Core populate the model from form values, route values, or query-string values; binding uses the first matching value it finds. section 16.2
- Validate the input before using it, and avoid [BindProperties], which binds every page property and can increase overposting risk. section 16.4
A page-specific input model
An edit page can expose [BindProperty] public InputModel Input { get; set; }, then place fields such as Category, Username, and ProductModel inside the nested InputModel class. The handler can accept a simple route parameter such as id directly. section 16.2 section 16.4
public class IndexModel: PageModel
{
[BindProperty]
public InputModel Input { get; set; }
public void OnGet()
{
}
public class InputModel
{
public string Category { get; set; }
public string Username { get; set; }
public ProductModel Model { get; set; }
}
}
Inspect the compact Razor Page definition that groups several bound values inside a nested InputModel. section 16.2
