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

Create a new attribute for Pages property binding #6091

Closed
rynowak opened this issue Apr 6, 2017 · 5 comments
Closed

Create a new attribute for Pages property binding #6091

rynowak opened this issue Apr 6, 2017 · 5 comments

Comments

@rynowak
Copy link
Member

rynowak commented Apr 6, 2017

We want to create a new attribute [BindProperty] which means that the property should be model bound.

We'll have an override via a property bool 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 to un-bind a property if you use the attribute at the class level.

This new attribute should go in the RazorPages namespace. Features like SupportsGet 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
}
@rynowak
Copy link
Member Author

rynowak commented Apr 6, 2017

Open question here - should we support this attribute on controllers? Should we add support for SupportsGet to the controller binding plumbing?

If we do these things there's no issue with needing to hide this attribute, it can go in the root MVC namespace.

@DamianEdwards
Copy link
Member

@danroth27 RE the putting this on Controllers question. I don't have an issue with it, given it seems so explicit, seems like we'd need a good reason not to support it.

@rynowak
Copy link
Member Author

rynowak commented Apr 7, 2017

seems like we'd need a good reason not to support it

I agree. One of our goals is not to introduce new pages only primitives.

@rynowak
Copy link
Member Author

rynowak commented Apr 21, 2017

For preview 1 we're adding this for Pages only and it will be in the .RazorPages namespace. We'll move it to the general MVC namespace in preview 2 and support it on controllers as well.

rynowak added a commit that referenced this issue Apr 21, 2017
rynowak added a commit that referenced this issue Apr 21, 2017
rynowak added a commit that referenced this issue Apr 21, 2017
rynowak added a commit that referenced this issue Apr 22, 2017
@rynowak
Copy link
Member Author

rynowak commented Apr 24, 2017

297196b

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants