Problem to fill date field with ASP.NET MVC, Razor

Asked

Viewed 117 times

1

I’m making a mini registration system, it has the place to edit a client’s registration, when I click edit it comes the data in the fields for me to edit, all fields comes normal, except the field date that comes empty.

I was seeing that in front-end the value comes in the tag value, but it does not appear in the system.

inserir a descrição da imagem aqui

Edit controller:

// GET: Cliente/Edit/5
public ActionResult Edit(int? id)
{
    if (id == null)
    {
        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
    }
    ClienteModel clienteModel = db.Clientes.Find(id);
    if (clienteModel == null)
    {
        return HttpNotFound();
    }
    return View(clienteModel);
}

// POST: Cliente/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "IdCliente,Nome,DataNascimento,Sexo,CEP,Logradouro,Complemento,Bairro,Estado,Cidade,Numero")] ClienteModel clienteModel)
{
    if (ModelState.IsValid)
    {
        db.Entry(clienteModel).State = EntityState.Modified;
        db.SaveChanges();
        return RedirectToAction("Index");
    }
}

data-birth field input(I am using Razor):

<div class="form-group">
    @Html.LabelFor(model => model.DataNascimento, "Data-Nascimento", htmlAttributes: new { @class = "control-label col-md-3" })
    <div class="col-md-10">
        @Html.EditorFor(model => model.DataNascimento, new { htmlAttributes = new { @class = "form-control col-md-3", placeholder = "DD/MM/AAAA", id = "datanascimento", OnBlur = "verificarDataNascimento(datanascimento.value)" } })
        @Html.ValidationMessageFor(model => model.DataNascimento, "", new { @class = "text-danger" })
    </div>
</div>

Can someone tell me if I’m doing something wrong ?

1 answer

0

I discovered the problem, the field only accepts the date format in yyyy-mm-dd and I was passing dd/mm/yyyy.

Browser other questions tagged

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