I would like everyone's help to help with the following problem:
Theerrorhappenswhenheisstilldoingthefieldvalidations.
Controller:
publicActionResultCreate(){varvEmpresas=newDictionary<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>