Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Created Unassigned: Model validation does not fail when validation attribute is on a field [1297]

$
0
0
__Repro Steps__
* Create webapi2 project
* Create a simple class with validation attribute on a field
public class Person
{
public int Id { get; set; }

[StringLength(4)]
public string MyName;

public string Name
{
get { return MyName; }
set { MyName = value; }
}
}
* Create a Webapi controller with EF for "Person".
* Now try to insert a Peron entity into database.

Expected: This fails.
Observed: It works fine.

On Webapi 1, I see following error when I follow steps above

ExceptionMessage=Field 'MyName' on type 'WebApplication2.Models.Person' is attributed with one or more validation attributes. Validation attributes on fields are not supported. Consider using a public property for validation instead.


Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>