NumericTextBoxFor.Step(decimal) for MVC wrappers

7 posts, 1 answers
  1. Brian
    Brian avatar
    6 posts
    Member since:
    Sep 2013

    Posted 23 Sep 2013 Link to this post

    I am attempting to put a 'Step' onto a NumericTextBoxFor.  Intellisense tells me to use a decimal value; however, using a decimal value throw an error:

    @Html.Kendo().NumericTextBoxFor(model => model.MyProperty).Step(0.01)
    It doesn't like the 0.01.  If I put an integer value (ex: 1), it does not give an error.  Why does it not like the decimal values?  
  2. Answer
    Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 25 Sep 2013 Link to this post

    Hi Brian,

    In C# 0.01 is treated as double and in case MyProperty is different type (i.e float or decimal) you will get an error. You can explicitly convert the step value to decimal using the following syntax:   
    .Step(0.01m)
     

    Regards,
    Alexander Popov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Brian
    Brian avatar
    6 posts
    Member since:
    Sep 2013

    Posted 25 Sep 2013 Link to this post

    Thank you for the help, Alexander.  That works perfectly.

    In case it might help someone else, here is what I have.  The formatting is:    xx.xxx %         with no rounding.

    @Html.Kendo().NumericTextBoxFor(model => model.MyProperty).Step(0.01m).Format("00.000 \\%").Decimals(5)
  5. David
    David avatar
    5 posts
    Member since:
    Jul 2009

    Posted 28 Jan 2015 Link to this post

    Old thread but I can´t figure out why my numeric textbox does not work with mvc wrapper.
    @(Html.Kendo().NumericTextBoxFor(m => m.AntalTimmar)
      .Culture("sv-SE") 
      .Format("#.0")
      .Step(0.5m)
      .Decimals(1)
    )

    In html5 / javascript it works perfect.
    <input id="numerictextbox" />
    $("#numerictextbox").kendoNumericTextBox({ 
       culture: "sv-SE",
       format: "#.0",
       step: 0.5,
       decimals: 1
    });

    The data type is decimal. What am I doing wrong with the mvc wrapper?

    Thank you!
  6. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 28 Jan 2015 Link to this post

    Hello David,

    Would you please tell us what is the result of using the code you shared? Are there any JavaScript errors in the console or the browser's network tab, that might give us a clue what goes wrong?

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  7. David
    David avatar
    5 posts
    Member since:
    Jul 2009

    Posted 28 Jan 2015 in reply to Alexander Popov Link to this post

    I am sorry, I forgot to mention what the problem is.
    The .Step(0.5m) does not work. The step becomes: 0.0 -> 5.0 -> 10.0 -> 15.0 and so on.....

    I am trying to make a step every half hour. Something like this: 0.0 -> 0.5 -> 1.0 -> 1.5 and so on....

    It works perfect in html5/javascript. The output should be the same for the wrapper, right?

    Probably it is something obvious=).

    Thanks!
  8. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 30 Jan 2015 Link to this post

    Hello David,

    I tried reproducing this using a decimal field and it works as expected (see screencast). I am really not sure what exactly is causing this, however I would suggest upgrading to the latest available version, as this might be an issue that is already addressed. In case this behavior persists after the upgrade I would ask you to share a small runnable project where the issue is isolated, so we can examine it locally. Meanwhile, you can initialize the widget using JavaScript as a workaround. 

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready