Hi, I'm new to C # and MVC ASP NET and I have the following complication. I'm trying to flatten the data of different models in a single view to use this data in a form, to all this I found that I can (mix?) Two models or more in a parent model and pull this new data from both models. ..
If this is the case, I have already tried but I can not do it.
These are my models:
using System.ComponentModel.DataAnnotations;
namespace PCotiza_compras.Models
{
public class Categories
{
public int Id { get; set; }
[Display(Name = "Nombre")]
public string Name { get; set; }
[Display(Name = "Descripción")]
public string Description { get; set; }
}
}
using System.ComponentModel.DataAnnotations;
namespace PCotiza_compras.Models
{
public class Departments
{
public int Id { get; set; }
[Display(Name = "Código")]
public string Code { get; set; }
[Display(Name = "Descripción")]
public string Description { get; set; }
}
}
In this other model I am trying to put the 2 together and I am also given other properties (I do not know if this is possible)
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace PCotiza_compras.Models
{
public class Requests
{
List<PCotiza_compras.Models.Departments> dep { get; set; }
List<PCotiza_compras.Models.Categories> cat { get; set; }
public int Id { get; set; }
public string Folio { get; set; }
public int UserId { get; set; }
[Display(Name = "Proyecto")]
public string Project { get; set; }
[Display(Name = "Esquema")]
public int SchemeId { get; set; }
[Display(Name = "Fecha")]
public string Date { get; set; }
[Display(Name = "Estado")]
public string Status { get; set; }
[Display(Name = "Días de expiración")]
public int ExpirationDays { get; set; }
[Display(Name = "Comentarios")]
public string Comments { get; set; }
[Display(Name = "Departamento")]
public int DepartmentId { get; set; }
[Display(Name = "Categoría")]
public int CategoryId { get; set; }
}
}
My error I left here on the Model saying that I lack of definition 'GetNumerator'
@model PCotiza_compras.Models.Requests
@{
ViewBag.Title = "Nueva solicitud";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<select class="form-control" id="sel1">
@{ int i = 1; }
@foreach (var item in Model.DepartmentId){
<option>
<strong>@Html.DisplayFor(modelItem => item.Code)</strong>
</option>
i = i + 1;
}
</select>
Thanks a lot to the whole community:)