0
I’m having trouble with Action Edit.
I have a class called Clientefirm this class has a System collection. For Example: The Customer X uses the systems To, C and F.
My problem is how to present these system in View Edit.
This is my View Get Edit
public ActionResult Editar(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
ClienteEmpresa clienteEmpresa = db.ClienteEmpresaDb.Find(id);
if (clienteEmpresa == null)
{
return HttpNotFound();
}
ViewBag.SistemasComerciais = clienteEmpresa.TipoDeSistemas.ToList();
ViewBag.RamoDeAtividade = clienteEmpresa.RamoAtividade;
return View(clienteEmpresa);
}
I tried to send in a viewBag, but gave this error
The Viewdata item that holds the 'Systemsmercial' key is of the type 'System.Collections.Generic.List`1[[Smc.Dominio.Model.Tipodesystems, Smc.Dominio, Version=1.0.0.0, Culture=neutral, Publickeytoken=null]', but it needs to be 'Ienumerable' type'.
This is the html that gets this list.
<div class="form-group" style="margin-left:-34px; margin-top:17px;margin-bottom:11px;">
<label for="vat" class=" form-control-label">Tipo De Sistema</label>
@Html.DropDownList("SistemasComerciais", null, htmlAttributes: new { @class = "standardSelect", multiple = "multiple", placeholder = "Selecione..." })
</div>
This is the code of the Tipodesistemas class:
public class TipoDeSistemas
{
[Key]
public int Id { get; set; }
[Required]
public string Descricao { get; set; }
public string Cod { get; set; }
[Required]
public DateTime DataCadastro { get; set; }
public virtual ICollection<ClienteEmpresa> ClienteEmpresa { get; set; }
}
Does anyone know how I can show this list of systems, which my client uses?
I didn’t understand very well, has how you do this helper there, with this data here.
@Html.DropDownList("SistemasComerciais", null, htmlAttributes: new { @class = "standardSelect", multiple = "multiple", placeholder = "Selecione..." })
– Rafael Passos
Try passing the data in one
IEnumerable
instead of aList
– Ronaldo Araújo Alves