Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't choose model validation rules without added a new model type. #3

Open
jnonce opened this issue Jun 16, 2015 · 0 comments
Open

Comments

@jnonce
Copy link
Owner

jnonce commented Jun 16, 2015

The existing model validation system doesn't allow a controller action to specify a model validator. Ideally we'd be able to say something like:

[HttpGet]
public IHttpActionResult Action1(
    [CustomizeValidator(RuleSet = "Rule1")]MyModel widget)
{
    return Ok();
}

[HttpGet]
public IHttpActionResult Action2(
    [CustomizeValidator(RuleSet = "Rule2")]MyModel widget)
{
    return Ok();
}

As is we're forced to introduce types like so:

[ValidateModel("Rule1")]
public class Action1Model : MyModel { }

[HttpGet]
public IHttpActionResult Action1(
    Action1Model widget)
{
    return Ok();
}

[ValidateModel("Rule2")]
public class Action2Model : MyModel { }

[HttpGet]
public IHttpActionResult Action1(
    Action2Model widget)
{
    return Ok();
}

FluentValidation supports this via a IModelBinder attribute in MVC, but has nothing comparable in WebApi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant