Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Allow BindPropertyAttribute to be specified on PageModel \ handler #6653

@jchadwick

Description

@jchadwick

The default model binding convention of PageModel classes should be that all properties are automatically candidates for model binding. Just like you do not have to specify the [Bind] attribute on controller action arguments in order for them to be model binding candidates, you shouldn't have to put [BindProperty] on the PageModel properties, either. Not only is opting in the opposite of the default MVC model binding behavior, it is implemented not through the BindAttribute but through an entirely different attribute, which means that developers need to learn two different approaches for the same basic functionality.

In addition to the cognitive overhead, it also has a negative impact on usability when combined with forms using XXXFor HTML helpers and Tag Helpers since these helpers operate off of the model defined by @model and @model would typically point to a PageModel code-behind. It's overbearing to have to put the [BindProperty] attribute on every single property, so I'm going to prefer creating another class to use as a single property and place [BindProperty] on that. This has the net effect of "namespacing" each of the form fields (what was name="FirstName" is now name="Customer.FirstName". Other than this "namespacing" being inefficient and introducing other subtle naming side-effects (e.g. browser form field autocomplete for standard fields like "password" no longer match), from a design/architecture standpoint this new class effectively becomes a view model within what's already supposed to be a view model, which gets awkward.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions