【发布时间】:2020-05-05 11:00:56
【问题描述】:
我想做的事情看起来很简单,但我遇到了一些麻烦。我创建了以下类:
// SelectedItem.cs
public class SelectedItem
{
public Brand Brand { get; set; }
public string Model { get; set; }
}
在我的视图页面中,我创建了一个 SelectedItem 列表:
// Chart.cshtml
@model Prediction.Models.Chart.ManualSelection
@{
@using Prediction.Models.Chart
List<SelectedItem> selectedItems = new List<SelectedItem>();
}
我正在尝试从我认为的 html 中添加到此列表中。我创建了一个表,它的行由 foreach 循环填充。
// Also Chart.cshtml, below the previous code section where I created the list
<table class="table table-borderless table-hover table-striped table-sm mb-0">
<tbody>
@foreach (var item in Model.PhoneInfo)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Brand)
</td>
<td>
@Html.DisplayFor(modelItem => item.Model)
</td>
<td>
<button type="button" class="btn btn-sm btn-link">Select</button>
</td>
</tr>
}
</tbody>
</table>
基本上我要做的是在单击按钮时,我希望将特定的item.Brand 和item.Model 添加到List<SelectedItem> selectedItems。
【问题讨论】:
-
只有在服务器端呈现视图时,您的列表才存在。页面呈现后发生的任何事情,例如按钮单击,都发生在客户端。
标签: c# asp.net .net asp.net-core razor