2

It seems Foolproof Validation does not work with 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; }
}

Fiddler:

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


{Id: 1, Condition: true}

Response:

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

The same code works fine with classic MVC 4 temaplate.

1 Answer 1

6

No, it wouldn't...

From a quick look at the source code here the FoolproofValidator is tied to the System.Web.Mvc namespace by inheritting from System.Web.Mvc.DataAnnotationsModelValidator so this library is not going to work for WebApi.

There is a DataAnnotationsModelValidator for System.Web.Http so it might be able to be ported across but I cannot see a branch or version on the project site that has done that yet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.