Fórum Como acrescentar Mascara no MVC #603499
06/07/2019
0
Boa Noite, como posso adicionar uma mascara no CNPJ, Agencia e CC no View Create do projeto? Estou agarrado tem um tempo já.
@model ProjetoWebCadastro.Models.cadastrofornecedor
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>cadastrofornecedor</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group ">
@Html.LabelFor(model => model.CNPJ, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CNPJ, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CNPJ, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.RazaoSocial, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.RazaoSocial, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.RazaoSocial, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NomeFantasia, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.NomeFantasia, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NomeFantasia, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Endereco, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Endereco, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Endereco, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Cidade, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Cidade, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Cidade, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Estado, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Estado, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Estado, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Telefone, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Telefone, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Telefone, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DataDeCadastro, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.DataDeCadastro, "{0:d mmm yyyy}", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DataDeCadastro, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Categoriaa, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Categoriaa, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Categoriaa, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Status, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Agencia, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Agencia, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Agencia, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ContaCorrente, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ContaCorrente, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ContaCorrente, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/inputmask")
}
Obrigado desde já!
@model ProjetoWebCadastro.Models.cadastrofornecedor
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>cadastrofornecedor</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group ">
@Html.LabelFor(model => model.CNPJ, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CNPJ, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CNPJ, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.RazaoSocial, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.RazaoSocial, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.RazaoSocial, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NomeFantasia, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.NomeFantasia, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NomeFantasia, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Endereco, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Endereco, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Endereco, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Cidade, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Cidade, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Cidade, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Estado, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Estado, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Estado, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Telefone, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Telefone, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Telefone, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DataDeCadastro, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.DataDeCadastro, "{0:d mmm yyyy}", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DataDeCadastro, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Categoriaa, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Categoriaa, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Categoriaa, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Status, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Agencia, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Agencia, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Agencia, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ContaCorrente, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ContaCorrente, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ContaCorrente, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/inputmask")
}
Obrigado desde já!

Alexandre
Curtir tópico
+ 2
Responder
Post mais votado
24/07/2019
Ei Alexandre, tudo bom ?
Então, para mascaras no C# eu uso a seguinte função Javascript:
para consumi-la faz o seguinte (exemplo no caso de CPF)
Basta adequar para CNPJ etc..
Abraço :)
Então, para mascaras no C# eu uso a seguinte função Javascript:
1 2 3 4 5 | $( function () { $( "input[data-tipo=''cpf'']" ).mask( "000.000.000-00" ); $( "input[data-tipo=''data'']" ).mask( "00/00/0000" ); $( "input[data-tipo=''moeda'']" ).mask( "000.000.000,00" , { reverse: true }); }); |
para consumi-la faz o seguinte (exemplo no caso de CPF)
1 2 3 4 5 | <div class = "form-group col-md-4" > @Html.LabelFor(model => model.CPF, htmlAttributes: new { @ class = "control-label" }) @Html.EditorFor(model => model.CPF, new { htmlAttributes = new { @ class = "form-control" , placeholder = "000.000.000-00" , data_tipo = "cpf" } }) @Html.ValidationMessageFor(model => model.CPF, "" , new { @ class = "text-danger" }) </div> |
Basta adequar para CNPJ etc..
Abraço :)
Stella Oliveira

Responder
Gostei + 4
Clique aqui para fazer login e interagir na Comunidade :)