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

Support model binding to Razor Pages properties on page and PageModel classes #5952

Closed
DamianEdwards opened this issue Mar 13, 2017 · 6 comments

Comments

@DamianEdwards
Copy link
Member

No description provided.

@pranavkm
Copy link
Contributor

Would we bind properties on the page and the model or just the model if both are available?

@DamianEdwards
Copy link
Member Author

It would be based on the presence of an attribute (let's start with ModelBinder is it?) but should match the behavior for page handler processing I think, I.e. does OnGet() on the page get called if I have a model?

@pranavkm
Copy link
Contributor

does OnGet() on the page get called if I have a model?

Nope. The model wins if it's present. Ok, seems straightforward, find properties with ModelBinder on the type that has the executing handler and bind them.

@DamianEdwards
Copy link
Member Author

Yep, let's start there and we'll tweak after use if necessary.

@pranavkm
Copy link
Contributor

@DamianEdwards \ @rynowak - what's the behavior for model binding in GET requests? Right now I have it enabled. However if you have models with validation, the ModelState is invalid at that point. I had to do things like:

@if (Context.Request.Method == "POST")
{
   @Html.ValidationSummary()
}

to avoid seeing validation errors on my first GET.

@pranavkm
Copy link
Contributor

Spoke to @DamianEdwards and @rynowak offline and we decided to not model bind properties on GET requests.

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

3 participants