Passing a string as an argument to a controller
-
06-07-2019 - |
Question
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.
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!
Is there a specific reason why strings are handled differently than ints?
Solution
It need to have the name 'id', as setup in the route's default config.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow