LP13
LP13

Reputation: 34109

Use DisplayFormatAttribute with Kendo NumericTextBox

I have model with DisplayFormat attribute

public class MyModel
{
    [DisplayFormat(DataFormatString = "{0:N2}", ApplyFormatInEditMode = true)]
    public decimal? Amount { get; set; }
}

In View i have

@(Html.Kendo().NumericTextBoxFor(m=> m.Amount ))

However that does not format the value in numeric text box.

If i change the view as

@(Html.Kendo().NumericTextBoxFor(m=> m.Amount).Format("N2"))

then it works.

However using Format in razor view is undesirable. I would like to handle formatting using data annotation attributes.

How can i use DisplayFormat attribute with Kendo MVC NumericTextBox control?

Note Based on telerik's forum post on 02 Oct 2014

After further consideration we decoded tp add a support for DataFormatString in the next official release of Kendo UI scheduled for the mid of next week. You can downloaded it once it is out and give it a try.

The version i'm using is v2016.3.1118 but it seems it still not working

Upvotes: 0

Views: 384

Answers (1)

Przemysław Kleszcz
Przemysław Kleszcz

Reputation: 646

I have prepared some tests on 2017.3.1026 version. Works perfectly for your example. Looks like your version still have problem with DataFormatString. Update should resolve your issue.

Upvotes: 0

Related Questions