Я застрял на этом почти 2 дня, я пытался решить проблему, но я не могу получить нужные данные.
Я новичок вASP.NET.Я хочу получать информацию о всех участниках определенного события всякий раз, когда нажимаю на детали (ссылку) события.
Я думаю, что я понял правильную логику, но я не могу написать ее в коде.
Это мой details.cshtml
файл:
@model MVCUML.Models.Registration
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<div>
<h4>Registration</h4>
<hr />
@Html.DisplayForModel(Model.Events.EventName)
<table>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayForModel(Model.Attendees.Name) </td>
</tr>
}
</table>
</div>
<p>
@Html.ActionLink("Back to List", "Index")
</p>
Это мой контроллер для регистрации / Подробности:
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Registration registration = db.Registrations.Find(id);
if (registration == null)
{
return HttpNotFound();
}
return View(registration);
}
namespace MVCUML.Models
{
public class Registration
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
public int EventId { get; set; }
[Required]
public int AttendeeId { get; set; }
public virtual Event Events { get; set; }
public virtual Attendee Attendees { get; set; }
}
}
public class Event
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
[Display(Name = "Event Name")]
public string EventName { get; set; }
[Required]
public string Location { get; set; }
[Required]
[Display(Name = "Event Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime EventDate { get; set; }
[Required]
[DisplayFormat(DataFormatString = "{0:C}")]
public Decimal Fee { get; set; }
public virtual ICollection<EventAssignment> EventAssignments { get; set; }
public virtual ICollection<Registration> Registrations { get; set; }
}
public class Attendee
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
[Display(Name = "First Name")]
public string FName { get; set; }
[Required]
[Display(Name = "Last Name")]
public string LName { get; set; }
public string Name
{
get { return string.Format("{0} {1}", this.FName, this.LName); }
}
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[Phone]
public string Phone { get; set; }
public virtual ICollection<Registration> Registrations { get; set; }
}
public class RegistrationIndexData
{
public IEnumerable<Event> Events { get; set; }
public IEnumerable<Attendee> Attendees { get; set; }
public IEnumerable<Registration> Registrations { get; set; }
}