Search code examples
razor-pageskendo-asp.net-mvc

How to update a Kendo NumericTextBox in a razor page with correct formatting?


I am trying to update Kendo NumericTextBoxes via the datamodel in my razor page. I have a field

@(Html.Kendo().NumericTextBoxFor(m => m.DataModel.FieldName)
                .Format("{0:C}")) 

and then try to update it with

$('#DataModel_FieldName').val(value).change()

The problem is when I update the code as shown above, it does not show the updated value on the front end unless I click the NumericTextBox.

It seems it may be holding two different values or something like that but I am expecting it to show the updated value without needing to click the NumericTextBox (This is how the Kendo TextBox works). I have tried numerous solutions and nothing seems to work so any help or ideas would be greatly appreciated, thanks!


Solution

  • I got it to work by using jQuery to get the Kendo NumericTextBox's data and then setting the value like this:

    let kendoNumericTextBox = $('#DataModel_FieldName').data('kendoNumericTextBox') 
    kendoNumericTextBox.value(value)