Put mask in @ Html.EditorFor [closed]

-4

In the database, the CPF field is bigint and long in the model. I have two problems with this: 1) If the cpf starts with 0 or 00, it will not record this and then, to display on the screen, I will have to use algon as padleft (11) or similiar. 2) Since I have a cshtml that was generated based on the model, then I am not able to generate the mask in the field to type cpf. The problem is that in the bank, I will have different field sizes, so when the cpf starts with 0 or 00 and so it goes, I know that this would not be the problems, thanks to padleft (11).

<div class="form-group">
        @Html.LabelFor(model => model.cpf, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.cpf, new { htmlAttributes = new { @class = "form-control", @id = "cpf" } })
            @Html.ValidationMessageFor(model => model.cpf, "", new { @class = "text-danger" })
        </div>
    </div>

With the code above, I am not able to mask the field, for the reasons already presented. Does anyone suggest?

    
asked by anonymous 10.08.2018 / 19:50

1 answer

1

You need to include the Jquery.inputmask script reference on your View .

$("#cpf").inputmask("mask", {
  "mask": "999.999.999-99"
}, {
  reverse: true
});
$("#nascimento").inputmask("mask", {
  "mask": "99/99/9999"
}, {
  reverse: true
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://rawgit.com/RobinHerbots/Inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>

<p>CPF: <input type="text" id="cpf" /></p>
<p>Nascimento: <input type="text" id="nascimento" /></p>
    
10.08.2018 / 20:34