I have a object property like this: public object Data { get; set; }
public object Data { get; set; }
And I have some input with different types in .razor
component:
switch (DataType)
{
case DataType.Boolean:
<input @bind="Data" type="checkbox" />
break;
case DataType.String:
<input @bind="Data" type="text" />
break;
case DataType.Number:
<input @bind="Data" type="number" />
break;
}
Аs a result I get error:
how can I bind these input to object property?
I had a similar problem and using @onchange
instead of @bind
resolved it.
switch (DataType)
{
case DataType.Boolean:
<input @onchange="@(x => { Data = x; })" type="checkbox" />
break;
case DataType.String:
<input @onchange="@(x => { Data = x; })" type="text" />
break;
case DataType.Number:
<input @onchange="@(x => { Data = x; })" type="number" />
break;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.