0
我想在一個表中顯示一組特定的N模型每個模型性能的有着多種模型對每個具體的屬性處理鑑於
我有以下型號:
卡
public enum Rarity
{
Legendary,
Epic,
Rare,
Common
}
public class Card
{
public int ID { get; set; }
public string Name { get; set; }
public bool Disenchant { get; set; }
public Rarity Rarity { get; set; }
public virtual ICollection<Deck> Decks { get; set; }
}
甲板
public class Deck
{
public int ID { get; set; }
public string Name { get; set; }
public virtual Card Card { get; set; }
public virtual Hero Hero { get; set; }
}
首頁的索引控制器:
個public ActionResult Index()
{
var db = new DustContext();
var cards = db.Cards.ToList();
return View(cards);
}
片段指數:
@model IEnumerable<App.Models.Card>
<tbody>
@foreach (var item in Model)
{
@Html.Partial("_CardList", item)
}
</tbody>
,最後我的部分:
@model CardApp.Models.Card
<tr>
<td>@Model.Name</td>
<td>@Model.Rarity</td>
<td>@Model.Disenchant</td>
</tr>
我怎樣才能在表格中顯示從卡模式(已在部分)的屬性一起有來自Deck模型的財產?我試過使用元組,但我得到列表和IEnumerable錯誤。
可能一個ViewBag工作過什麼?對不起,我很新。 – Onilol
是的,我想如果你想將你的模型放回到視圖包中,然後將視圖包放入視圖中,那就行了。但是,正確的方法和最佳實踐是使用視圖模型來處理服務器端代碼和視圖表單之間的交互。 – mituw16
我的意思是......因爲我只想揭露Deck模型(Name)的一個特定屬性。 – Onilol