简体   繁体   中英

Integer parameter gets default value when passing string in url

I've got a controller action like this:

[HttpGet("test/{value}")]
public object Get(int value)
{
    return new {value};
}

When I make a request to http://localhost:53615/test/asdf I was expecting the action to not be invoked and instead get a 404 response. But instead it is invoked with 0 as value.

Is there any way to get the behaviour I'm expecting?

如果找不到匹配项,则对参数的约束将导致返回404:

[HttpGet("test/{value:int")]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM