-1

I currently am trying to pass a value to a controller action and the integer i am trying to pass is too long. To overcome this, I have tried using new { trackingNumber = 9374869903500896631228d } and changing the parameter type of my action to a double but then the value is passed in as 9.3748699035009E+21 instead of 937486990350089663128. How can I change the below Html.ActionLink and controller action so that I can pass the value 937486990350089663128to my action?

Action Link:

<div>@Html.ActionLink("Track Package", "TrackPackage", "Orders", new { trackingNumber = 9374869903500896631228 }, null)</div>

Controller Action:

public void TrackPackage(int trackingNumber) { // .....do stuff with trackingNumber }

GregH
  • 5,125
  • 8
  • 55
  • 109

1 Answers1

1

There is no simple type in c# that can hold a integral number that big (long resp. Int64 only have about 18 digits). And double, although it has the range for such a big number, lacks the precision. So you can only pass the value as a string. If you need arithmetic operations on the number on the server side, you can use the BigInteger structure. You can convert the string into a BigInteger using the Parse method.

public void TrackPage(string trackingnumber) {
    BigInteger tracker = BigInteger.Parse(trackingnumber);   
    // do something with your number 
}
derpirscher
  • 14,418
  • 3
  • 18
  • 35