0
I have this foreach, which I did with your help here at SOPT. I cost to make it work, but it worked. Only I did it with just one knot. What I’m going to need is this. I have a father knot, inside that father knot a son, inside the son a grandson and so on. My model returns me all the required fields. I have tried to do it in several ways and they all make a mistake in the tag, because it says the message that it is not possible to nest tags the way I am doing. Look at this, this code below, I can bring all the reasons.
<ul>
@foreach (var item in Model)
{
<li item-checked='false' item-expanded='false'>
@item.Motivo
</li>
}
</ul>
Now I need to bring in this reason, the trade units_business. These values or data come from the same Model, would be more or less like this:
<ul>
<li item-checked='false' item-expanded='false'>
@item.Unidade_Negocio
</li>
</ul>
However, if I put this code inside the foreach
main gives tag error <ul>
. But from my little experience, I’m gonna need a tag <ul>
to position Unidade_negocio, and more, precise, to my understanding of another foreach only for Unidade_negocio. Then I can’t walk anymore. This whole job is because I couldn’t make it work jquery
, because by my jquery
already brings everything in each
, but I couldn’t assemble the checks and so I’m working directly on cshtml(view)
.
I did so as Miguel suggested, but it is a mistake:
<ul>
@foreach (var item in Model)
{
<li item-checked='false' item-expanded='false'>
@item.Motivo
</li>
<li>
<ul>
@foreach (var negocio in Model.Unidade_Negocio)
{
<li item-checked='false' item-expanded='false'>
@negocio.Unidade_Negocio
</li>
}
</ul>
</li>
}
</ul>
The mistake is this:
Additional information: 'object' não contém uma definição para 'Unidade_Negocio'
This is my Action with the Bible. It’s a general Action.
public ActionResult Acao()
{
RupturaEntities db = new RupturaEntities();
var monta_arvore = db.Ruptura.Where(m => m.IDMotivo != 6)
.Select(rup=>
new MontaArvoreAcao{
IDRuptura = rup.IDRuptura,
DataRuptura = rup.DataRuptura,
IDMotivo = rup.IDMotivo,
Motivo = rup.Motivo.Motivo1,
IDOrigem = rup.IDOrigem,
CodigoPDV = rup.CodigoPDV,
UF = rup.PDV.UF,
Cidade = rup.PDV.Cidade,
CnpjDescricao= rup.PDV.Cnpj + " - " + rup.PDV.Descricao,
Codigo_Apresentacao = rup.Codigo_Apresentacao,
Unidade_Negocio = rup.Apresentacao.Unidade_Negocio,
Franquia = rup.Apresentacao.Franquia,
Familia = rup.Apresentacao.Familia,
Descricao = rup.Apresentacao.Descricao
}).ToList().Take(50);
return View(monta_arvore);
}
That’s the way it is now:
<ul>
@foreach (var item in Model)
{
<li item-checked='false' item-expanded='false'>
@item.Motivo
<ul>
<li item-checked='false' item-expanded='false'>
@item.Unidade_Negocio
<ul>
<li item-checked='false' item-expanded='false'>
@item.Familia
<ul>
<li item-checked='false' item-expanded='false'>
@item.Descricao
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
}
</ul>
Don’t change the question after you get an answer. So you invalidate mine and it gets confusing for someone who comes to read the question for the first time, changing the initial problem you had
– CesarMiguel
This change that changes the meaning of the question. First the error was of the
ul
, now it is error to go through the foreach– CesarMiguel