Using jquery field mask in ASP.net Core MVC

Asked

Viewed 364 times

1

I am working on a CRM project with C# Asp.net core with Mysql and I am already with bank ready and everything straight and I made the client registration form and I am in the validation part now.

I want to put mask to CPF/CNPJ, telefone, cep and everything else and downloaded in the package manager nuget the jQuery Input Mask as in the image:

https://prnt.sc/vuluei

I’m wearing this macoratti tutorial, but it’s for ASP NET MVC and he asks for the following Open the folder App_Start and include the script below at the end of the Bundleconfig.Cs file :, but my project is ASPNET CORE and does not have the bundleconfig.cs.

I wonder if this is the best way to put mask and how to proceed to put on ASPNET CORE

Observing: I tried referencing in Folder Layout shared and use the mask and gives error.

1 answer

1


The way the installation is not done yet for ASPNET CORE, so follow these steps:

  • Download the package on the website [ download ] :

  • Unzip in a directory and search for the folder dist/ that has the code jquery.inputmask.js.

  • Add this file inside your ASPNET CORE project folder wwwroot/js/

  • Inside your project folder shared has its layout with the name _Layout.cshtml at the end of that file the reference of that file, example:

    <script src="~/js/jquery.inputmask.js"></script>
    

to use do as in the example:

$(document).ready(function() {
  $("#data").inputmask('99/99/9999');
  $("#cpf").inputmask('999.999.999-99');
  $("#cnpj").inputmask('99.999.999/9999-99');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://rawgit.com/RobinHerbots/Inputmask/5.x/dist/jquery.inputmask.js"></script>

<input type="text" id="data" /><br />
<input type="text" id="cpf" /><br />
<input type="text" id="cnpj" /><br />


  • Thank you very much!

  • If it’s useful to vote as a solution to your question! @Vitorlima

  • 1

    I don’t know how to vote as a solution, I’m trying here.

Browser other questions tagged

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