aspnetcore/test/Microsoft.AspNet.Mvc.Integr...
Harsh Gupta 53ef8258bb The model state keys for body bound models which are bound at property 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).
2015-04-22 14:02:08 -07:00
..
BodyValidationIntegrationTests.cs The model state keys for body bound models which are bound at property will use the entire model name with this change for example 2015-04-22 14:02:08 -07:00
Microsoft.AspNet.Mvc.IntegrationTests.xproj The model state keys for body bound models which are bound at property will use the entire model name with this change for example 2015-04-22 14:02:08 -07:00
ModelBindingTestHelper.cs The model state keys for body bound models which are bound at property will use the entire model name with this change for example 2015-04-22 14:02:08 -07:00
TestMvcOptions.cs The model state keys for body bound models which are bound at property will use the entire model name with this change for example 2015-04-22 14:02:08 -07:00
project.json The model state keys for body bound models which are bound at property will use the entire model name with this change for example 2015-04-22 14:02:08 -07:00