This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The model state keys for body bound models which are bound at propert…
…y will use the entire model name with this change for example Consider public class Person { [FromBody] public Address Address { get; set; } } public class Address { [Required] public string Street { get; set; } public int Zip { get; set; } } Request body { "Zip" : 12345 } In this case the error key would be "prefix.Address.Street" (assuming there is a prefix because of additional metadata/positioning for/of the Person model). public class Person { [Required] public string Name { get; set; } } public void Action([FromBody]Person p) { } Request body { } In this case the prefix gets ignored and the error key is Name. Please note this is so that we are compatible with MVC 5.0 public class Person { [Required] public string Name { get; set; } } public void Action([FromBody][ModelBinder(Name = "prefix")] Person p) { } public void Action2([FromBody][Bind(Name = "prefix")] Person p) { } Request body { } In both these cases (Action and Action2) the prefix gets ignored and the error key is Name. This is a slight improvement from mvc, as in MVC the action parameter would be null. The followup for this would be to fix #2416 - This PR ignores the validation assuming that #2416 will address the issues and update the test. NOTE: previous versions of mvc did not have property binding and hence there is no precedence in this case. For MVC and Web API it was possible to body bind an action parameter which used an empty prefix instead of a parameter name for adding errors to model state (In case of MVC if a custom prefix was provided, it failed binding from body i.e the parameter was null).
- Loading branch information
1 parent
323ec2f
commit ec21283
Showing
11 changed files
with
476 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.