我正在尝试访问模型的列表变量中的变量,但最后无法访问变量。访问FirstName的正确方法是什么,即
@Html.TextBoxFor(m => Model.CustomerBasket.OrderLines[i].DelegatesList.FirstName)
当前代码:
<div class="basket-item-delegate__input-cell">
<h6>First Name:</h6>
@Html.TextBoxFor(m => Model.CustomerBasket.OrderLines[i].DelegatesList)
</div>
Inside DelegatesList中有FirstName,LastName和Email。该字段的想法将在DelegatesList中设置值。
模特片段:
public int EventId { get; set; }
public int CourseId { get; set; }
[Required(ErrorMessage = "Quantity must be a number")]
public int Quantity { get; set; }
public List<OrderDelegate> DelegatesList { get; set; }
OrderDelegate cs:
public class OrderDelegate
{
[Key]
public int OrderLineId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
答案 0 :(得分:0)
@ Html.TextBoxFor(m =&gt; Model.CustomerBasket.OrderLines [i] .DelegatesList [j] .FirstName)
答案 1 :(得分:0)
DelegatesList
是List<OrderDelegate>
,在这种情况下,您必须像
Model.CustomerBasket.OrderLines[i].DelegatesList[i].FirstName