0
我正在創建一個幫助臺軟件的網頁,其中頂部顯示票務類中的信息,然後顯示通過ICollection附加到票證類的票證底部。目前,如果我註釋掉底部,則頂部(靜態表)可以正常工作。但是,指向ICollection的底部兩個表格不起作用。下面是我得到的錯誤:兒童班級不能使用的枚舉列表
這是我的觀點:
@model HelpDesk.Model.Ticket
@{
ViewBag.Title = "Ticket# " + Html.DisplayFor(model => model.TicketNumber);
}
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.CategoryId)
</th>
<th>
@Html.DisplayFor(model => model.Category.CategoryName)
</th>
</tr>
<tr>
<th>
@Html.DisplayNameFor(model => model.OpenUserId)
</th>
<th>
@Html.DisplayFor(model => model.OpenUser.FullName)
</th>
</tr>
<tr>
<th>
@Html.DisplayNameFor(model => model.OpenDate)
</th>
<th>
@Html.DisplayFor(model => model.OpenDate)
</th>
</tr>
<tr>
<th>
@Html.DisplayNameFor(model => model.TechnicianId)
</th>
<th>
@Html.DisplayFor(model => model.Technician.FullName)
</th>
</tr>
<tr>
<th>
@Html.DisplayNameFor(model => model.TicketStatusId)
</th>
<th>
@Html.DisplayFor(model => model.TicketStatus.StatusDescription)
</th>
</tr>
<tr>
<th>
@Html.DisplayNameFor(model => model.CloseDate)
</th>
<th>
@Html.DisplayFor(model => model.CloseDate)
</th>
</tr>
<tr></tr>
</table>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.TicketNotes.Note)
</th>
<th>
@Html.DisplayNameFor(model => model.TicketNotes.TicketNoteDate)
</th>
<th>
@Html.DisplayNameFor(model => model.TicketNotes.UserNote.FullName)
</th>
<th></th>
</tr>
@foreach (var item in Model.TicketNotes)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.TicketNotes.Note)
</td>
<td>
@Html.DisplayFor(modelItem => item.TicketNotes.TicketNoteDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.TicketNotes.UserNote.FullName)
</td>
</tr>
}
</table>
這是我的控制器代碼:
public ActionResult EditUserTicket(Guid id)
{
Ticket ticket = tickets.GetById(id);
var model = db.Tickets
.Include(t => t.TicketNotes)
.Where(t => t.TicketId == id).First();
return View(model);
}
,這裏是我的模型:
namespace HelpDesk.Model
{
public class Ticket
{
public Ticket()
{
this.TicketNotes = new HashSet<TicketNote>();
}
public Guid TicketId { get; set; }
[Display(Name = "#")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Required]
public int TicketNumber { get; set; }
[ForeignKey("Category")]
[Required]
public Guid CategoryId { get; set; }
public virtual Category Category { get; set; }
[ForeignKey("OpenUser")]
[Required]
public Guid OpenUserId { get; set; }
[Display(Name = "Ticket Owner")]
public virtual User OpenUser { get; set; }
[Display(Name = "Opened")]
[DataType(DataType.Date)]
[Required]
public DateTime OpenDate { get; set; }
[ForeignKey("Technician")]
[Required]
public Guid TechnicianId { get; set; }
[Display(Name = "Technician")]
public virtual User Technician { get; set; }
[ForeignKey("TicketStatus")]
[Required]
public Guid TicketStatusId { get; set; }
public virtual TicketStatus TicketStatus { get; set; }
[Display(Name = "Closed")]
[DataType(DataType.Date)]
public Nullable<DateTime> CloseDate { get; set; }
[Display(Name = "Note")]
public virtual ICollection<TicketNote> TicketNotes { get; set; }
//public virtual ICollection<TicketSubscription> TicketSubscriptions { get; set; }
}
}
可能重複[DisplayNameFor()從型號列表
只是'@ Html.DisplayFor(m => item.Note)'等('item'已經是'TicketNote')。只是硬編碼'
@StephenMuecke工作完美。我現在要清理視圖。你是男人。 – djblois
回答
在你
foreach
循環item
已經是TicketNote
一個實例,因此因爲
TicketNote
沒有一個名爲TicketNotes
這應該只是
屬性失敗表格標題,您可以使用
來源
2015-06-09 02:26:15
相關問題