質問

I read through these posts

DataAnnotation for Required property

http://forums.asp.net/t/1835627.aspx/1

and I understand it has something to do with xml and not supporting required but I don't get why this is an issue.

I have a View Model that has a Required attribute over a Guid and that is what is causing the problem. I just don't get how the xml factors into this as the request is REST so where does the xml come in play to cause this problem.

役に立ちましたか?

解決

The validator was added as a security measure because all Web APIs accept XML by default. And because the XML formatter doesn't raise model state errors for missing required members, you could end up in a situation where a required member was missing and yet the model state was valid.

With that said, this behavior has caused a lot more trouble than it's worth. So it is gone in the current nightly builds, and it won't be there in the next version of Web API. In the meantime, you can disable it with this line:

config.Services.RemoveAll(typeof(System.Web.Http.Validation.ModelValidatorProvider),v => v is InvalidModelValidatorProvider);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top