how to show a list with a master structure-detail MVC

1

You want to show all the details of a certain project, for this you have the following tables

in the Outputs table the headers (projects) are saved and in the table Outputs Details are saved (list of products of different projects)

The following view is available for the user to enter the name of the project and the different details for that project are displayed by clicking on the button

com can I pass a list of OutputsDetails to my view "CloseProject.cshtml"? for example in the first image if the user enters the project Kn_CodigoProyecto = 3, I have to display the details Kn_CodeDetailsDetail = 2,3,4,5

Although I get ID'S from the Output table as shown in the following figure

How can I find those ID'S in my table OutputsDetails and display them in my view?

My ActionResults:

 [HttpGet]
        public ActionResult CierreProyecto(int? page)
        {           
            ViewBag.Kn_CodigoProyecto = new SelectList(CombosHelper.GetProyectos(), "Kn_CodigoProyecto", "v_Nombre");

            var view = db.SalidaDetalles.ToList();
            view.Clear();
            return View(view.ToPagedList(page ?? 1, 50));           
        }

        [HttpPost]
        public ActionResult CierreProyecto(int? page, string searchTerm)
        {
            List<SalidaDetalle> resultado;

            //consulto codigo proyecto
            var codigoproyecto = db.Proyectos.Where(n => n.v_Nombre == searchTerm).Select(c => c.Kn_CodigoProyecto).FirstOrDefault();

            //consulto en que maestro esta el proyecto ingresado por usuario
            var listamaestro = db.Salidas.Where(c => c.Kn_CodigoProyecto == codigoproyecto).Select(c => c.Kn_CodigoSalida).ToList();

            foreach(var item in listamaestro)
            {
                resultado = db.SalidaDetalles.Where(c => c.Kn_CodigoSalida == listamaestro).ToList();
            }

            ViewBag.Kn_CodigoProyecto = new SelectList(CombosHelper.GetProyectos(), "Kn_CodigoProyecto", "v_Nombre");

            return View(resultado.ToList().ToPagedList(page ?? 1, 50));          
        }

View:

@using PagedList;
@using PagedList.Mvc;
@model IPagedList<SistemaBodega.Models.SalidaDetalle>

<h2>Cerrar Proyecto</h2>

<!DOCTYPE html>

<html>
<head>

</head>

<body>
    @using (Html.BeginForm("CierreProyecto", "Salidas", FormMethod.Post))
    {
        <div class="form-horizontal">        

            <hr />

            <div class="col-md-4">
                <div class="form-group">
                    <label>Proyecto</label>
                    @Html.TextBox("searchTerm", null, new { @class = "form-control", id = "txtSearch", placeholder = "Nombre Proyecto" })

                  </div>
            </div>

            <div class="col-md-8">
                <div class="form-group">
                    <button class="btn btn-warning" id="mybtn" type="submit">
                        Buscar Proyecto
                        <i class="glyphicon glyphicon-search"></i>
                    </button>

                </div>
            </div>

        </div>

    }

    <hr />

    <table class="table table-hover table-bordered table-responsive">
        <thead>
            <tr>
                <th style="text-align:center">Codigo</th>
                <th style="text-align:center">Producto</th>
                <th style="text-align:center">Cantidad</th>
            </tr>

        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <th style="text-align:center">@item.Kn_CodigoProducto </th>
                    <th style="text-align:center">@item.v_Nombre</th>
                    <th style="text-align:center">@item.d_Cantidad</th>                  
                </tr>             
            }
        </tbody>
    </table>
</body>
</html>

I know the foreach is doing something wrong, how can I show the user the list of products of a certain project? Any help for me?

    
asked by fytoahse 19.03.2018 в 20:13
source

1 answer

0

This line does not make sense:

   resultado = db.SalidaDetalles.Where(c => c.Kn_CodigoSalida == listamaestro).ToList();

Well masterlist a line above is a set of data

 foreach(var item in listamaestro)

In any case, it will be listmaster. SOMEWHERE, but matching a code to a set of data does not fit me, I do not know if that's where your error goes.

    
answered by 26.03.2018 в 16:21