2013-03-01 47 views
2

似乎万无一失的验证不会与WEB API工作:MVC万全验证与ASP.NET MVC WEB API项目

// POST api/values 
public void Post(MyModel model) 
{ 
}  

public class MyModel 
{ 
    public int Id { get; set; } 
    public bool Condition { get; set; } 
    [RequiredIfFalse("Condition")] 
    public string Title { get; set; } 
} 

提琴手:

User-Agent: Fiddler 
Content-Type: application/json; charset=utf-8 
Host: localhost:3858 
Content-Length: 24 


{Id: 1, Condition: true} 

响应:

{"Message":"An error has occurred.","ExceptionMessage":"The method or operation is not implemented.","ExceptionType" 

相同的代码与经典的MVC 4 temaplate可以很好地协作。

回答

5

没有,也不会......

从快速查看源代码hereFoolproofValidator由来自System.Web.Mvc.DataAnnotationsModelValidator inheritting绑在System.Web.Mvc命名空间,这样此库不上班为WebApi。

有一个DataAnnotationsModelValidatorSystem.Web.Http所以它可能是能够越过被移植,但我不能看到已经这么做了项目现场的分支或版本。