Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • bob baty-barr 1180 posts 1294 karma points MVP
    Jun 28, 2012 @ 22:42
    bob baty-barr
    0

    razor and math functions with data from xml

    Hopefully this is a simple one...

    i have an xml chunk i am reading in with razor...

    <RangeShown lower="1" upper="11"/>

    all i want to do is subract lower from upper... but i am having issues casting the strings as numbers...

    so i get this...

    String upper doc.SelectSingleNode("/SearchResults/RangeShown/@upper").Value;
      String lower doc.SelectSingleNode("/SearchResults/RangeShown/@lower").Value;

    and i want to change them into ints so i can do some simple math..

    int upperLimit upper;
      int lowerLimit lower;
      int numPerPage =  upperLimit lowerLimit;

    but the int statements for upperLimit and lowerLimit obviously error... please help me to understand razor better ;)

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Jun 28, 2012 @ 22:46
    Morten Bock
    0

    I'm no razor guru, but if it is anything like regular C#, you should be able to do:

    int upperLimit = int.Parse(upper);

    and so on...

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jun 28, 2012 @ 22:56
    bob baty-barr
    1

    yeah it was wierd... int.Parse() was not working -- throwing an error... however 

    Convert.ToInt32() worked great... grrrr

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Jun 28, 2012 @ 23:00
    Morten Bock
    0

    Lovely :-)

    Maybe because of the capitalised "String" instead of "string".

    Anyways, good to know :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies