0

Hi Im new to MVC5 and I just want to ask how can I add the attribute for my Editor so i can add phone mask in it

Heres the code

 @Html.EditorFor(model => model.PhoneNumber, new { htmlAttributes = new { @class = "form-control" } })

and heres the attribute that i want to add

data-mask="(999) 999-9999"

I tried it in a simple input and it works

 <input type="text" class="form-control" data-mask="(999) 999-9999" placeholder="Phone">

Thanks in advance

7
  • 1
    new { htmlAttributes = new { @class = "form-control", data_mask = "(999) 999-9999" } } (underscore will be converted to hyphen by razor engine) Commented Feb 20, 2017 at 6:31
  • 1
    @StephenMuecke what is data_mask? just curious. Commented Feb 20, 2017 at 6:34
  • 1
    @CodingYoshi, A attribute used by a jquery plugin I assume, but I don't which one :) Commented Feb 20, 2017 at 6:39
  • @StephenMuecke i just tried data_mask and it doesn't work. Commented Feb 20, 2017 at 6:46
  • 1
    What does not work? - It will add data-mask="(999) 999-9999" assuming your using MVC-5.1+. Otherwise use @Html.TextBoxFor(m => m.PhoneNumber, new { @class = "form-control", data_mask = "(999) 999-9999", placeholder = "Phone" }) Commented Feb 20, 2017 at 6:50

1 Answer 1

0
new { htmlAttributes = new { @class = "form-control", data_mask = "(999) 999-9999" } }

(underscore will be converted to hyphen by razor engine)

great answer by user3559349

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.