This repository was archived by the owner on Dec 14, 2018. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork2.1k
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
Create a new attribute for Pages property binding #6091
Closed
Description
We want to create a new attribute[BindProperty] which means that the property should be model bound.
We'll have an override via a propertybool SupportsGet which enables binding of the properties for GET requests.
Placing the attribute on a class means that it applies to all public properties in the class. This has overriding behavior - the attribute on the property wins. There is no way toun-bind a property if you use the attribute at the class level.
This new attribute should go in the RazorPages namespace. Features likeSupportsGet aren't relevant to controllers.
Examples:
public class Index : PageModel{ [BindProperty] public string CustomerName { get; set; } // This property is only bound for non-GET requests}public class Search : PageModel{ [BindProperty(SupportsGet = true)] public string Query { get; set; } // This property is bound for all requests}[BindProperty(SupportsGet = true)]public class Search : PageModel{ public string Query { get; set; } // This property is bound for all requests public bool ImFeelingLucky { get; set; } // This property is bound for all requests}