Search code examples
textboxdevexpressmasking

DevExtreme: TextBox: Set Mask to a Model property


Is it possible to set the mask of a devextreme textbox field to a model's property? As in bind the mask property to a model's property value?

For example:

Model:

public MyClass{ 
public string PhoneNumber{get; set;}
public string PhoneMask{get; set; } = "+1 (999) 000-0000"; 
}

View: 
@(Html.DevExtreme().TextBox()
//                    .Mask("+1 (X00) 000-0000")
                    .Mask(Model.PhoneMask)
                    .Value(Model.PhoneNumber)
                    .InputAttr("aria-label", "Mask")
                    
                )

Solution

  • Yes, it is possible. It appears that you already do something similar. Make sure that you pass a correct Model (with the initialized / expected PhoneMask property value). Check out how the TextBox().Mask() builder method works at https://demos.devexpress.com/ASPNetCore/Demo/TextBox/Overview/