This is a migrated thread and some comments may be shown as answers.

NumericTextBoxFor.Step(decimal) for MVC wrappers

6 Answers 1487 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 23 Sep 2013, 05:12 PM
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?  

6 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Popov
Telerik team
answered on 25 Sep 2013, 12:42 PM
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!
0
Brian
Top achievements
Rank 1
answered on 25 Sep 2013, 03:30 PM
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)
0
David
Top achievements
Rank 1
answered on 28 Jan 2015, 11:13 AM
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!
0
Alexander Popov
Telerik team
answered on 28 Jan 2015, 11:26 AM
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!
 
0
David
Top achievements
Rank 1
answered on 28 Jan 2015, 11:36 AM
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!
0
Alexander Popov
Telerik team
answered on 30 Jan 2015, 09:17 AM
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!
 
Tags
NumericTextBox
Asked by
Brian
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Brian
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or