Problem with Masked Fields

Asked

Viewed 50 times

0

Hello, I’m using the plugin masked input to mask some fields of the kind decimal!

However, when I submit the form this field arrives as null in the class controller. I’ve searched and I can’t find anything about it.

Could someone help me? Thanks in advance.

Follows the code.

Model

 [Display(Name = "Telefone")]
 public decimal? TELEFONE_FUN { get; set; }

Controller

[HttpPost]
        public ActionResult Add_Funcionarios(FUNCIONARIOS funcionario)
        {
            if (ModelState.IsValid)
            {
                //recupera o nome do usuario da sessao
                GRAgro.Models.USUARIOS usuario =        (GRAgro.Models.USUARIOS)Session["usuario"];
                string nome = User.Identity.Name;

                // seta o id do usuario vindo da sessao
                funcionario.ID_USU = UsuarioCont.PegaIdUsuarioLogado(nome);
                FuncionarioRep.Add_Funcionarios(funcionario);

                cadHistorico(historico, funcionario,"Cadastro do Funcionario(a):");
                TempData["Feedback_cadastro"] = "Funcionario "+funcionario.NOME_FUN+" Cadastrado com Sucesso!";
                return RedirectToAction("CadastradoComSucesso", "Feedback");
            }
            else
            {
                TempData["teste"] = "nao cadastrado";
                return View();
            }
        }

View

<div class="form-group">
                                    @Html.LabelFor(model => model.TELEFONE_FUN)
                                    @Html.TextBoxFor(model => model.TELEFONE_FUN, new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.TELEFONE_FUN)
                                </div>

Jquery

$("#TELEFONE_FUN").mask("(99) 99999-9999");
  • If you remove Mask, it arrives correctly?

  • Enough, so I’m intrigued, and when in my model the attribute is string it arrives in the normal controller, but masked

  • Where are you waiting for it to arrive on the model? You shouldn’t put a property in Action?

  • It arrives in the null controller action!

1 answer

0


Hello, if I understand correctly the "TELEFONE_FUN" is declared in the model as number, then when you pass the masked value goes the parentheses and the hyphen together, then bad. Try to "clear" it before sending or declare the "TELEFONE_FUN" field so that it can receive these characters.

  • I have another field string Cpf, when I debug the code this brings the parentheses and the hyphen is clean and is blz, but this decimal comes null does not bring anything!

  • Okay, have you tried changing this decimal phone field to string to see if it works? Anyway I didn’t understand the reason to use decimal type for a phone.

  • A string model like vc made in Cpf can receive hifen, whereas decimal cannot. Is that not what is making return null?

  • I created the field with string in the model without mapping to the bank, so it receives well I do the conversation and insert in the bank It worked! Thanks people

Browser other questions tagged

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