Make a foreach inside a cshtml

0

It is giving error the way I did the foreach. If you put @ gives error in the analyzer. If retreat gives other errors. How I do? Below is my complete code.

@model Ruptura.Models.RupturaEntities

@{
    ViewBag.Title = "CadastroCargo";
    Layout = "~/Views/Shared/_LayoutBase.cshtml";
}

<link href="~/Content/Jqwidgets/jqx.base.css" rel="stylesheet" />
<link href="~/Content/Jqwidgets/jqx.summer.css" rel="stylesheet" />

<br />

<h3>Cadastro de Cargos</h3>

<br />

<div class="container">
    <div class="row">
        <div class="col-md-12">
            @*<div class="col-md-1">
                    <label for="txtCargo">Cargo:</label>
                </div>*@
            <div class="col-md-4">
                <input type="text" class="form-control col-md-6" name="txtCargo" id="txtCargo" placeholder="Digite um cargo válido">
            </div>
        </div>

        <br /><br />

        <div class="col-md-6">
            <h3 class="text-center">Unidade de negócio</h3>';
            <div class="well" style="max-height: 350px;overflow: auto;">
                <ul class="list-group checked-list-box" id="check-list-box">

                    @{
                        foreach (var rpt in Model.Apresentacao)
                        {
                            <li class="list-group-item" data-style="button" data-color="success">rpt.Unidade_Negocio</li>
                        }
                    }

                </ul>
            </div>
        </div>

        <div class="col-md-6">
            <br /><br /><br />
            <div class="well" style="max-height: 300px;overflow: auto;">
                <ul class="list-group list-box">
                    <li class="list-group-item" data-style="button">Gerente Região Norte</li>
                    <li class="list-group-item" data-style="button" data-color="success">Gerente Região Sul</li>
                    <li class="list-group-item" data-style="button" data-color="info">Gerente São Paulo</li>
                </ul>
            </div>
        </div>

        <div class="col-md-12">
            <div class="col-md-6">
                <label class="checkbox" for="ckbAtivo">
                    <input type="checkbox" checked="checked" class="checkbox large" data-label="suffix" data-label-prepend="prefix" name="ckbAtivo" id="ckbAtivo">Ativo
                </label>
            </div>
        </div>

    </div>

            <div id="content">
                <div class="listTree"></div>
                <button class="btn btn-success" onclick=" return GravaCargo();">Gravar</button>
                @Html.ActionLink("Voltar", "Index", "Home", new { }, new { @class = "btn btn-danger" })
            </div>
        </div>

        <script src="~/Scripts/CheckListBox/CheckListBox.js"></script>
        <script src="~/Scripts/CadastroCargo/CadastroCargo.js"></script>

I did this and the error continues:

@{
   if(Model.Apresentacao != null)
   { 
      foreach (var rpt in Model.Apresentacao){
      @:<li class="list-group-item" data-style="button" data-color="success">@rpt.Unidade_Negocio</li>
    }
 }

}

    
asked by anonymous 26.08.2014 / 19:41

2 answers

1
<div class="well" style="max-height: 350px;overflow: auto;">
                <ul class="list-group checked-list-box" id="check-list-box">

                    @foreach (var rpt in Model.Apresentacao)
                        {
                            <li class="list-group-item" data-style="button" data-color="success">@rpt.Unidade_Negocio</li>
                        }
                    }

                </ul>
            </div>
    
26.08.2014 / 19:46
0

I solved it like this:

<ul class="list-group checked-list-box" id="check-list-box">

                    @{
                        Ruptura.Models.RupturaEntities db = new Ruptura.Models.RupturaEntities();
                        var result_ap = db.Apresentacao
                            .Select(a => new { a.Codigo_Unidade_Negocio, a.Unidade_Negocio }).ToList().Distinct();


                        foreach (var item in result_ap)
                        { 
                            <li class="list-group-item" data-style="button" data-color="success">@item.Unidade_Negocio</li>
                        }
                    }
    
27.08.2014 / 19:44