我要作出這樣的MVC頁面的模型:的foreach沒有找到嵌套類
public class Body
{
public int Id { get; set; }
public class Hand
{
public List<Fingers> fingers { get; set; }
}
public class Foot
{
public List<Toes> toes { get; set; }
}
public class Head
{
public Nose nose {get; set;}
public List<Ears> ears { get; set; }
public List<Eyes> eyes { get; set; }
}
}
然後對手指一類是這樣的:
public class Fingers
{
public int Id { get; set; }
public string Description { get; set; }
}
然後訪問它像這樣在我看來:
@model Models.Body
@foreach (var fingers in Model.Hand.Fingers)
{
@Html.RadioButton("fingerList", fingers.Description)
}
我在做我的模型錯了嗎?現在VS不承認foreach
中的Model.Hand
,更不用說Model.Hand.Fingers
。我不想讓@model
IEnumerable
因爲這個頁面只顯示一個person
,但它可以有fingers
,toes
多個列表等
什麼是錯誤?它不comp'le?或者在執行時間手指不顯示? – DanielVorph