1

I would like to check if my variable is an integer in controller. In view I can easily use isInt() but not in the controller. Do I need to have a special reference to use that method?

Thank you.

bobek
  • 8,003
  • 8
  • 39
  • 75
  • I want to return view with path as argument, but first I need to know if the path is a number or not. In view I can use `Where(x=>x.path.IsInt() == true)`, but in controller I think I need a reference so I can use that method. – bobek Sep 06 '11 at 15:05

2 Answers2

2

If you add the following namespace you can use it in your controller.

using System.Web.Webpages;

Depending on your usage you might want to use Int32.TryParse() instead.

Bengel
  • 1,043
  • 7
  • 12
2
int result;
if (int.TryParse(x, out result))
{
    // do something with result, which is a "strong" int
}
Ofer Zelig
  • 17,068
  • 9
  • 59
  • 93