-2
Controller:
public ActionResult Cadastrar()
{
ViewBag.officelist = new SelectList(new OfficeREP().ListarTodos(),
"id",
"estado"
);
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Cadastrar(OpportunityMOD opportunidade)
{
if (ModelState.IsValid)
{
var opportunity01 = new OpportunityREP();
opportunity01.Salvar(opportunidade);
TempData["mensagem"] = "Cadastro realizado com Sucesso!";
return RedirectToAction("Index");
}
return View(opportunidade);
}
Model
[DisplayName("Escritório")]
public string officeId { get; set; }
View
<div class="col-md-2">
@Html.LabelFor(model => model.officeId)
@Html.DropDownListFor(model => model.officeId,(SelectList)ViewBag.officeList, string.Empty, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.officeId, "", new { @class = "text-danger" })
The funny thing that was working normal, now stopped and accuses this mistake... I do not understand what happened. It normal list when recording it gives this error.
– Rodrigo Borghi
Removes this line @Html.Dropdownlistfor(model => model.officeId,(Selectlist)Viewbag.officeList, string.Empty, new { @class = "form-control" })
– PauloHDSousa
I took it, but there’s no list, okay.
– Rodrigo Borghi
So, you’re trying to generate a LIST of a STRING, that’s the problem
– PauloHDSousa
Okay, more like I’ll list the objects and write as a string in the database. Because before it listed and writes, you know tell me ?
– Rodrigo Borghi
List a list and not a string
– PauloHDSousa
Still unsuccessful.
– Rodrigo Borghi
As you have listed?
– PauloHDSousa
Let’s go continue this discussion in chat.
– PauloHDSousa