小编Kan*_*ane的帖子

ASP .NET CORE simple parameter validation

I have implemented model validation in some of my APIs, but I was wondering if it is possible to do some validation using attributes on simple parameters, like:

[HttpGet("test/{type}")]
public ActionResult  GetSomeData([Range(0,2)]byte type)
{
  if (!ModelState.IsValid)
  {
    // isValid is always TRUE
  }
  ...
}
Run Code Online (Sandbox Code Playgroud)

When you call /controller/test/4, IsValid is always TRUE.

Is there a clean way to do that?

Thanks!

c# validation asp.net-core

1
推荐指数
2
解决办法
3109
查看次数

标签 统计

asp.net-core ×1

c# ×1

validation ×1