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
Model state has spurious entries when binding to a collection where element type has no validators. #2446
Comments
The model state entries should represent the structure of the posted data as opposed to how they were bound. |
Also need to check what exactly happens today in MVC5 / MVC6 for the scenarios listed above, plus this one: public ActionResult Foo(Person[] people)
{
}
public class Person : IValidatableObject
{
} |
MVC 5.0 For public ActionResult Foo(Person[] people)
{
}
public class Person : IValidatableObject
{
public string Name { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (Name == "c")
{
yield return new ValidationResult("c is not allowed.");
}
yield break;
}
} if there are three people bound For the other scenario listed in the bug, MVC 5.0 does not add the key with parameter name. (adds only what is bound). |
harshgMSFT
added a commit
that referenced
this issue
May 13, 2015
The assumption is ModelState should have entries if 1. An error is explicitly added by a model binder. 2. There is validation error reported while validating the model. 3. There is value bound by the model binder. With this change there should be no extra entry other than for the cases mentioned above. Also enabling the integration test cases.
@harshgMSFT could you please clarify the MVC 5 / 6 differences in these scenarios? |
harshgMSFT
added a commit
that referenced
this issue
May 14, 2015
The assumption is ModelState should have entries if 1. An error is explicitly added by a model binder. 2. There is validation error reported while validating the model. 3. There is value bound by the model binder. With this change there should be no extra entry other than for the cases mentioned above. Also enabling the integration test cases.
harshgMSFT
added a commit
that referenced
this issue
May 14, 2015
The assumption is ModelState should have entries if 1. An error is explicitly added by a model binder. 2. There is validation error reported while validating the model. 3. There is value bound by the model binder. With this change there should be no extra entry other than for the cases mentioned above. Also enabling the integration test cases.
harshgMSFT
added a commit
that referenced
this issue
May 15, 2015
The assumption is ModelState should have entries if 1. An error is explicitly added by a model binder. 2. There is validation error reported while validating the model. 3. There is value bound by the model binder. With this change there should be no extra entry other than for the cases mentioned above. Also enabling the integration test cases.
harshgMSFT
added a commit
that referenced
this issue
May 15, 2015
The assumption is ModelState should have entries if 1. An error is explicitly added by a model binder. 2. There is validation error reported while validating the model. 3. There is value bound by the model binder. With this change there should be no extra entry other than for the cases mentioned above. Also enabling the integration test cases.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Consider the following scenario
Input
Header: a, b, c
In this case there should be the following keys in the model state
Header[0]
Header[1]
Header[2]
but there a spurious entry for
Header
as well which should not be there.This would be the case even for simple scenarios like so
Query string is
parameter[0]=foo
in this case there would be two entries
parameter[0]
and
parameter
The text was updated successfully, but these errors were encountered: