Radzen Name and Component的问题是它不支持复杂类型。根据Henk Holtermans的建议,这里将是如何使工作
我有一个Foreach,其中包含RadzenNumeric和验证。我遇到的问题是Foreach中每个项目的名称和组件都相同。因此,如果10个中有1个值,那么它们都不会显示验证错误。
问题是,使名称独一无二的最佳方法是什么?有没有一种方法可以在Foreach中创建Counter,并将该值添加到Name和Componentet的末尾?
@foreach (Models.Ingredients.MeasuredIngredient measuredIngredient in CompoundIngredient.MeasuredIngredients)
{
<div class="ingredient-seperator"></div>
<div class="row ingredient">
<div class="amountInput col-6 col-md-2">
<RadzenNumeric class="newInput" Name="Amount" @bind-Value="measuredIngredient.Amount" TValue="decimal" Min="0"></RadzenNumeric>
<RadzenRequiredValidator class="rz-message rz-messages-error rz-message-popup newInputValidation" Component="Amount" Text="Amount is required" DefaultValue="0" Popup="true" />
</div>
</div>
}
应该可以对它们进行编号。
@{ var index = 0; }
@foreach (Models.Ingredients.MeasuredIngredient measuredIngredient in CompoundIngredient.MeasuredIngredients)
{
index += 1;
<RadzenNumeric class="newInput" Name="@("Amount"+index)" @bind-Value="measuredIngredient.Amount" TValue="decimal" Min="0"></RadzenNumeric>
<RadzenRequiredValidator class="rz-message ..." Component="@("Amount"+index)" Text="Amount is required" ... />
}
@{
int i = 0;
string amount = "Amount" + i.ToString();
string type = "Type" + i.ToString();
string ingredient = "Ingredient" + i.ToString();
}
@foreach (Models.Ingredients.MeasuredIngredient measuredIngredient in CompoundIngredient.MeasuredIngredients)
{
<div class="ingredient-seperator"></div>
<div class="row ingredient">
<div class="amountInput col-6 col-md-2">
<RadzenNumeric class="newInput" Name="@(amount)" @bind-Value="measuredIngredient.Amount" TValue="decimal" Min="0"></RadzenNumeric>
<RadzenRequiredValidator class="rz-message rz-messages-error rz-message-popup newInputValidation" Component="@(amount)" Text="Amount is required" DefaultValue="0" Popup="true" />
</div>
</div>
i++;
amount = "Amount" + i.ToString();
type = "Type" + i.ToString();
ingredient = "Ingredient" + i.ToString();
}