Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

I Have problem in ICollection ASP CORE

$
0
0

Good morning, I have a question about something I am trying to develop, the project is in ASP CORE 3.1 MVC. I have 2 identities one to one and the other (which is the one with problems) from one to many. What happens is that I am adding a company (Company Model) and those responsible for this company (Company Responsable Model) which are the following:

publicpartialclassEmpresa{publicintEmpresaId{get;set;}publicstringNombreEmpresa{get;set;}publicstringNumeroDistribuidor{get;set;}publicstringUbicacion{get;set;}publicstringRazonSocial{get;set;}publicstringDomicilio{get;set;}publicstringTelefono{get;set;}publicstringCorreo{get;set;}publicintCantidadEmpleados{get;set;}publicstringFechaAlta{get;set;}publicstringHoraAlta{get;set;}publicstringFechaModificacion{get;set;}publicstringHoraModificacion{get;set;}publicstringUsuarioAlta{get;set;}publicstringUsuarioModificacion{get;set;}publicbool?Estado{get;set;}publicvirtualNaturalezaEmpresaNaturalezaEmpresa{get;set;}publicICollection<ResponsableEmpresa>ResponsableEmpresas{get;set;}}}

Model ResponsableEmpresa:

publicintResponsableEmpresaId{get;set;}publicstringPuesto{get;set;}publicstringNombre{get;set;}publicstringApellidoMaterno{get;set;}publicstringApellidoPaterno{get;set;}publicstringCorreo{get;set;}publicstringTelefono{get;set;}[ForeignKey("Empresa")]publicintEmpresaId{get;set;}publicvirtualEmpresaEmpresa{get;set;}

Now, what I try is that in the view I can add the data of the company and separate those responsible, which would be the following view:

@modelEmpresa<h1 class="text-center">Datos generales de la empresa o grupo</h1><form asp-action="Guardar" asp-controller="Empresa" method="post"><div class="form-group col"><label>Nombre de la empresa:</label><input type="text" asp-for="NombreEmpresa"class="form-control"/><span asp-validation-for="NombreEmpresa"class="text-danger"></span></div><div class="form-group col"><label>Número de distribuidor:</label><input type="text" asp-for="NumeroDistribuidor"class="form-control"/><span asp-validation-for="NumeroDistribuidor"class="text-danger"></span></div><div class="form-group col"><label>Ubicación:</label><input type="text" asp-for="Ubicacion"class="form-control"/><span asp-validation-for="Ubicacion"class="text-danger"></span></div><div class="form-group col"><label>Razón Social:</label><input type="text" asp-for="RazonSocial"class="form-control"/><span asp-validation-for="RazonSocial"class="text-danger"></span></div><div class="form-group col"><label>Domicilio:</label><input type="text" asp-for="Domicilio"class="form-control"/><span asp-validation-for="Domicilio"class="text-danger"></span></div><div class="form-group col"><label>Telefono:</label><input type="tel" asp-for="Telefono"class="form-control"/><span asp-validation-for="Telefono"class="text-danger"></span></div><div class="form-group col"><label>Correo:</label><input type="email" asp-for="Correo"class="form-control"/><span asp-validation-for="Correo"class="text-danger"></span></div><div class="form-group col"><label>Cantidad de empleados:</label><input type="number" asp-for="CantidadEmpleados"class="form-control"/><span asp-validation-for="CantidadEmpleados"class="text-danger"></span></div><div class="form-group col"><label>Cantidad de empleados:</label><input asp-for="ResponsableEmpresas.Add(@responsableEmpresa)"class="form-control"/></div>@*<h1 class="text-center">ResponsableEmpresa</h1><p><br /><br /></p><table id="myTable"class="table table-bordered text-center"><thead><tr><td scop="col">Puesto</td><td scop="col">Nombre</td><td scop="col">ApellidoMaterno</td><td scop="col">ApellidoPaterno</td><td scop="col">Correo</td><td scop="col">Telefono</td></tr></thead><tbody><tr></tr></tbody></table><br><script>function myFunction(){var table = document.getElementById("myTable");
                table.contentEditable =true;var row = table.insertRow(2);var cell1 = row.insertCell(0);var cell2 = row.insertCell(1);var cell3 = row.insertCell(2);var cell4 = row.insertCell(3);var cell5 = row.insertCell(4);var cell6 = row.insertCell(5);
                cell1.innerHTML ="Ingresar Puesto";
                cell2.innerHTML ="Ingresar Nombre";
                cell3.innerHTML ="Ingresar Apellido Materno";
                cell4.innerHTML ="Ingresar Apellido Paterno";
                cell5.innerHTML ="Ingresar Correo ";
                cell6.innerHTML ="Ingresar Teléfono";}function myDeleteFunction(){
                document.getElementById("myTable").deleteRow(2);}function showTableData(){//gets tablevar oTable = document.getElementById('myTable');//gets rows of tablevar rowLength = oTable.rows.length;//loops through rowsfor(i =0; i < rowLength; i++){//gets cells of current rowvar oCells = oTable.rows.item(i).cells;//gets amount of cells of current rowvar cellLength = oCells.length;//loops through each cell in current rowfor(var j =0; j < cellLength; j++){// get your cell info herevar cellVal = oCells.item(j).innerHTML;if(cellVal.toString()!="Puesto"&& cellVal.toString()!="Nombre"&& cellVal.toString()!="Nombre"&& cellVal.toString()!="Apellido Materno"&& cellVal.toString()!="Apellido Paterno"&& cellVal.toString()!="Correo"&& cellVal.toString()!="Telefono"){
                            alert(cellVal);}}}}</script>*@<div class="row float-right" style="margin: 10px 5px 5px 5px"><a><input type="button" onclick="myFunction()"class="btn btn-info float-right"value="Insertar"/></a></div><div class="row float-right" style="margin: 10px 5px 5px 5px"><a><input type="button" onclick="myDeleteFunction()"class="btn btn-danger float-right"value="Borrar"/></a></div><div class="row float-right" style="margin: 10px 5px 5px 5px"><a><input type="button" onclick="showTableData()"class="btn btn-danger float-right"value="Leer"/></a></div><div class="row"><button type="submit"class="btn btn-primary float-right">Guardar</button></div></form>

The idea is that a number of managers can be added, but I cannot find a way to add it that when returning to the controller brings the information of Company Responsible .

Basically the idea is to pass an array from the view to the controller, but I have the problem handling the ICollection

Thanks a lot!


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>