我需要显示工作机会的列表,但不显示下拉列表,而是显示foreach,以便显示所有要约,但不要让我在模型中出现GetEnumerator错误。如何显示清单? (具有OfertaPostulante的关系与OfertaLaboral和AspNetUsers):
查看创建
@model ProyectoBase4.Models.OfertaPostulante
@{
ViewBag.Title = "Postulación";
}
<br /><br /><br />
<h2>Postulación</h2>
<hr />
<body id="body" class="dark-mode">
<div id="content body" class="dark-mode">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4><br /><br />Por favor, debe corroborar los datos para generar la postulación, luego hacer click en "Postular" para generar el registro:</h4>
<hr />
@foreach(var item in Model)
{
}
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.OfPostOf_ID, "OfPostOf_ID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("OfPostOf_ID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.OfPostOf_ID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.OfPostUsr_ID, "OfPostUsr_ID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.Display("OfPostUsr_ID")
@Html.ValidationMessageFor(model => model.OfPostUsr_ID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.OfPostFecha, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.OfPostFecha, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.OfPostFecha, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Postular" class="btn btn-primary" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
</div>
OfertaPostulante模型
namespace ProyectoBase4.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class OfertaPostulante
{
public int OfPost_ID { get; set; }
[Display(Name = "Oferta")]
public Nullable<int> OfPostOf_ID { get; set; }
[Display(Name = "Usuario")]
public string OfPostUsr_ID { get; set; }
[Display(Name = "Fecha Postulación")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> OfPostFecha { get; set; }
[Display(Name = "Usuario")]
public virtual AspNetUsers AspNetUsers { get; set; }
[Display(Name = "Oferta Laboral")]
public virtual OfertaLaboral OfertaLaboral { get; set; }
}
}
OfertaLaboral模型
namespace ProyectoBase4.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class OfertaLaboral
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public OfertaLaboral()
{
this.OfertaPostulante = new HashSet<OfertaPostulante>();
}
public int Of_ID { get; set; }
[Display(Name = "Rut Empresa")]
[Required]
public Nullable<int> OfEmp_ID { get; set; }
[Required]
[Display(Name = "Titulo")]
public string Of_Titulo { get; set; }
[Required]
[Display(Name = "Puesto")]
public string Of_Puesto { get; set; }
[Required]
[Display(Name = "Area")]
public Nullable<int> Of_Area { get; set; }
[Required]
[Display(Name = "Subarea")]
public Nullable<int> Of_Subarea { get; set; }
[Required]
[Display(Name = "Descripción")]
public string Of_Descrp { get; set; }
[Required]
[Display(Name = "Lugar")]
public string Of_Lugar { get; set; }
[Required]
[Display(Name = "Vacante")]
public Nullable<int> Of_Vacante { get; set; }
[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyy}", ApplyFormatInEditMode = true)]
[Display(Name = "Fecha Inicio")]
public Nullable<System.DateTime> Of_FechaIn { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyy}", ApplyFormatInEditMode = true)]
[Display(Name = "Fecha Fin")]
public Nullable<System.DateTime> Of_FechaFin { get; set; }
[Required]
[Display(Name = "Salario")]
public Nullable<int> Of_Salario { get; set; }
[Required]
[Display(Name = "Jornada")]
public Nullable<int> Of_Jornada { get; set; }
[Required]
[Display(Name = "Movilidad")]
public Nullable<int> Of_Mov { get; set; }
[Required]
[Display(Name = "Educación")]
public Nullable<int> Of_Edu { get; set; }
[Required]
[Display(Name = "Tipo contrato")]
public Nullable<int> Of_TContrato { get; set; }
[Required]
[Display(Name = "Estado")]
public Nullable<int> Of_Estado { get; set; }
[Display(Name = "Area")]
public virtual Area Area { get; set; }
[Display(Name = "Educación")]
public virtual Educacion Educacion { get; set; }
[Display(Name = "Estado")]
public virtual Estado Estado { get; set; }
[Display(Name = "Jornada")]
public virtual Jornada_Compl Jornada_Compl { get; set; }
[Display(Name = "Movilidad")]
public virtual Movilidad Movilidad { get; set; }
[Display(Name = "Subarea")]
public virtual Subarea Subarea { get; set; }
[Display(Name = "Tipo Contrato")]
public virtual TipoContrato TipoContrato { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
[Display(Name = "Oferta")]
public virtual ICollection<OfertaPostulante> OfertaPostulante { get; set; }
}
}
Controller OfertaPostulante / create
public ActionResult Create()
{
ViewBag.OfPostUsr_ID = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>().FindByName(User.Identity.Name).Email;
ViewBag.OfPostOf_ID = new SelectList(db.OfertaLaboral, "Of_ID", "Of_Titulo");
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "OfPost_ID,OfPostOf_ID,OfPostUsr_ID,OfPostFecha")] OfertaPostulante ofertaPostulante)
{
if (ModelState.IsValid)
{
db.OfertaPostulante.Add(ofertaPostulante);
var Datetimenow = DateTime.Now;
ofertaPostulante.OfPostFecha = new DateTime(Datetimenow.Year, Datetimenow.Month, Datetimenow.Day, Datetimenow.Hour, Datetimenow.Minute, 0);
ofertaPostulante.OfPostUsr_ID = HttpContext.User.Identity.GetUserId();
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.OfPostUsr_ID = new SelectList(db.AspNetUsers, "Id", "Email", ofertaPostulante.OfPostUsr_ID);
ViewBag.OfPostOf_ID = new SelectList(db.OfertaLaboral, "Of_ID", "Of_Titulo", ofertaPostulante.OfPostOf_ID);
return View(ofertaPostulante);
}
我需要在OfertaPostulante的“创建”视图中显示该列表,以便用户可以查看和选择要约