Inputmask for Displayfor

Asked

Viewed 1,628 times

2

I use jQuery Inputmask to add masks to my Textbox. However, 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 the same.

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, but I just need to list the data in a datatable, and the textbox doesn’t suit me.

@Html.TextBoxFor(model => model.sTelefone)

1 answer

2


Use something simpler. A ToString() formatted solves everything:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.