0
I would like the help of all to assist in the following problem:
The error happens when it is still validating the fields.
Controller:
public ActionResult Create()
{
var vEmpresas = new Dictionary<string, string>();
vEmpresas.Add("Matriz", "Matriz");
vEmpresas.Add("Filial1", "Filial1");
vEmpresas.Add("Filial2", "Filial2");
ViewBag.Empresas = vEmpresas;
return View(model: new Suporte { Empresa = "Matriz"});
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Codigo,DataInicio,DescProblema,Empresa,Solicitante,Atendente,CodAtendimento,CodChamado,Solucao,Status")] Suporte suporte)
{
if (ModelState.IsValid)
{
db.SuporteAts.Add(suporte);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(suporte);
}
View:
<div class="form-group">
@Html.LabelFor(model => model.Empresa, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Empresa, new SelectList(ViewBag.Empresas, "key", "value",selectedValue: null) , new { @class = "form-control" } )
@Html.ValidationMessageFor(model => model.Empresa, "", new { @class = "text-danger" })
</div>
</div>
This happens before saving or after?
– Barbetta
What do you mean when you are validating? It was not clear, even load the page with the drop-down?
– Barbetta