将字符串作为参数传递给控制器

时间:2021-08-07 18:47:25

I know this is probably really obvious, but I cannot figure out why I cannot pass a string argument to a controller like one would an int.

我知道这可能是非常明显的,但我无法弄清楚为什么我不能将字符串参数传递给控制器​​,就像一个int一样。

e.g.

//controller/action/2
public ActionResult Action(int someInt)
{
//somenumber != null
}

but when i pass a string in like this...

但是当我像这样传递一个字符串时......

//controller/Action/x9294kskw
public ActionResult Action(string someString)
{
//someString = null
}

What am I missing? I'm guessing this has to do with routing but...I have no idea. Thanks!

我错过了什么?我猜这与路由有关但......我不知道。谢谢!

edit:

Maybe I read over scott gu's blog a little too carelessly, but is this documented somewhere? I should have checked the routes!

也许我对scott gu的博客有点过于粗心,但这是在某处记录的吗?我应该检查路线!

Is there a specific reason why strings are handled differently than ints?

是否有一个特定的原因为什么字符串的处理方式与整数不同?

1 个解决方案

#1


It need to have the name 'id', as setup in the route's default config.

它需要具有名称“id”,作为路由默认配置中的设置。

#1


It need to have the name 'id', as setup in the route's default config.

它需要具有名称“id”,作为路由默认配置中的设置。