我想在循环中将值绑定到我的列表中的元素,但我找不到好的解决方案。
<EditForm Model="@dailyReport" OnValidSubmit="@SubmitDailyReport">
<p>
<label>Count: </label>
<InputNumber min="1" id="numberOfEffects" @bind-Value="numberOfEffects" />
</p>
@{
for (int i = 1; i <= numberOfEffects; i++)
{
if (effects.Count < i)
{
effects.Add("");
}
if (effects.Count > i)
{
effects.RemoveAt(effects.Count - 1);
}
string concatId = "effect" + i.ToString();
<p>
<label for="@concatId">@i</label>
<InputText id="@concatId" @bind-Value="effects.ElementAt(i-1)" />
</p>
}
}
//rest code
</EditForm>
Run Code Online (Sandbox Code Playgroud)
当我尝试将值绑定到列表中的元素时,出现错误:
我想知道是否有任何可能的方法将数据绑定到集合。我需要它,因为我的模型有一个 List 类型的属性。在我的输入表单中,我希望允许添加用户需要的尽可能多的字符串。
@code
{
private DailyReport dailyReport = new DailyReport();
private List<string> …Run Code Online (Sandbox Code Playgroud)