I'm doing a job for college with asp.net core MVC , and I'm using entity to generate the view and queries in the BD. I need to put masks in the fields like CNPJ. I got searching on Google how to put mascara, but when I try to create a record, it gives the error because of the mask.
I would like to know how to remove the mask and send the numbers to the DB.
View:
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="RazaoSocial" class="control-label"></label>
<input asp-for="RazaoSocial" placeholder="Razão Social" class="form-control" , />
<span asp-validation-for="RazaoSocial" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="NomeFantasia" class="control-label"></label>
<input asp-for="NomeFantasia" placeholder="Nome Fantasia" class="form-control" />
<span asp-validation-for="NomeFantasia" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Cnpj" class="control-label"></label>
<input asp-for="Cnpj" placeholder="Somente Numero" data-mask="00.000.000/0000-00" data-mask-reverser="false" class="form-control" />
<span asp-validation-for="Cnpj" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Ie" class="control-label"></label>
<input asp-for="Ie" placeholder="Somente Numero" class="form-control" />
<span asp-validation-for="Ie" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Avançar" class="btn btn-default" />
</div>
</form>
</div>
Controller
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("EmpresaId,RazaoSocial,NomeFantasia,Cnpj,Ie")] Empresa empresa)
{
if (ModelState.IsValid)
{
_context.Add(empresa);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(empresa);
}