C
C#6mo ago
mikibanan

@oninput problem

input class="clean-input" type="number" value="@item.ProductAttributes.FirstOrDefault(pa => pa.AttributeId == 1)?.Value"
@oninput="@(args => UpdateAttributeValue(item, 1, (string)args.Value!))"/>
input class="clean-input" type="number" value="@item.ProductAttributes.FirstOrDefault(pa => pa.AttributeId == 1)?.Value"
@oninput="@(args => UpdateAttributeValue(item, 1, (string)args.Value!))"/>
private async Task UpdateAttributeValue(Product product, int attributeId, string value)
{
Console.WriteLine($"Product: {product.Name}, AttributeId: {attributeId}, Value: {value}");
var attribute = product.ProductAttributes.FirstOrDefault(pa => pa.AttributeId == attributeId);

if (attribute is not null)
{
attribute.Value = value;
DbContext.ProductAttributes.Update(attribute);
await DbContext.SaveChangesAsync();
}
else
{
DbContext.ProductAttributes.Add(new ProductAttribute
{
ProductId = product.ProductId,
AttributeId = attributeId,
Value = value
});
await DbContext.SaveChangesAsync();
}
}
private async Task UpdateAttributeValue(Product product, int attributeId, string value)
{
Console.WriteLine($"Product: {product.Name}, AttributeId: {attributeId}, Value: {value}");
var attribute = product.ProductAttributes.FirstOrDefault(pa => pa.AttributeId == attributeId);

if (attribute is not null)
{
attribute.Value = value;
DbContext.ProductAttributes.Update(attribute);
await DbContext.SaveChangesAsync();
}
else
{
DbContext.ProductAttributes.Add(new ProductAttribute
{
ProductId = product.ProductId,
AttributeId = attributeId,
Value = value
});
await DbContext.SaveChangesAsync();
}
}
My @Oninput does not work. What may cause this?
1 Reply
Angius
Angius6mo ago
It's OnInput not @oninput