You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
Request body ""
In this case the error key would be "" and not "prefix.Address" (assuming there is a prefix because of additional metadata/positioning for/of the Person model).
Also the model state dictionary incorrectly has two keys
Key 1 : ""
Key 2 : Address -> This gets added because the validator looks for a key Address and not "" to determine if validation has been done for property Address.
In this case there should have been only two keys Address and it should be invalid.
Request body { "Street" : "Some street" }
In this case the error key would be "Street" and not "prefix.Address.Street" (assuming there is a prefix because of additional metadata/positioning for/of the Person model).
Also the model state dictionary incorrectly has three keys
Key 1 : ""
Key 2 : Street
Key 3: Zip -> This gets added as a valid entry because the validator looks for a key Zip and not "" to determine if validation has been done for property Zip.
In this case there should have been only two keys Address.Street and Address.Zip and the second one should be invalid.
The fix for this we would have to make the model state keys consistent with the rest of the model binding system. In all cases it should add the full prefixed version as the error key.
…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).
Consider the following two examples :
Example 1
Request body
""
In this case the error key would be
""
and not "prefix.Address" (assuming there is a prefix because of additional metadata/positioning for/of the Person model).Also the model state dictionary incorrectly has two keys
Key 1 :
""
Key 2 :
Address
-> This gets added because the validator looks for a keyAddress
and not""
to determine if validation has been done for propertyAddress
.In this case there should have been only two keys Address and it should be invalid.
Example 2
Request body { "Street" : "Some street" }
In this case the error key would be "Street" and not "prefix.Address.Street" (assuming there is a prefix because of additional metadata/positioning for/of the Person model).
Also the model state dictionary incorrectly has three keys
Key 1 :
""
Key 2 :
Street
Key 3:
Zip
-> This gets added as a valid entry because the validator looks for a keyZip
and not""
to determine if validation has been done for propertyZip
.In this case there should have been only two keys Address.Street and Address.Zip and the second one should be invalid.
The fix for this we would have to make the model state keys consistent with the rest of the model binding system. In all cases it should add the full prefixed version as the error key.
The fix to this might require #2330 to be fixed.
The text was updated successfully, but these errors were encountered: