2013-03-01 48 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所以它可能是能夠越過被移植,但我不能看到已經這麼做了項目現場的分支或版本。