InputMask for DisplayFor

2

I use jQuery Inputmask to add masks to my TextBox. But I need to add a mask when listing these fields (phone, cpf, etc). I use DisplayFor to list, but the mask does not work with it.

Code in my View:

                Cargo: @Html.DisplayFor(model => model.sTelefone)

JavaScript Function:

<script>

jQuery(function ($) {
    $("#sTelefone").mask("9999-9999");
});

Now when I use TextBoxFor, the mask works normally, however I only need to list the data in a dataTable, and the textBox does not answer me.

@Html.TextBoxFor(model => model.sTelefone)
    
asked by anonymous 22.01.2015 / 13:13

1 answer

2

Use something simpler. A% formatted% resolves all:

@Model.sTelefone.ToString(@"0000\-0000")

No need to format by JavaScript because the field will appear static.

    
22.01.2015 / 13:34