I have created a simple Blazor component (.NET Core 3.1, Blazor server apps) with a public parameter:
[Parameter]
public IReadOnlyCollection<Resource> Services { get; set; }
Run Code Online (Sandbox Code Playgroud)
I fill this parameter from a .cshtml page:
<component type="typeof(ActivityView)" render-mode="ServerPrerendered" param-Services="Model.Services" />
Run Code Online (Sandbox Code Playgroud)
The model property has the same type:
public IReadOnlyCollection<Resource> Services { get; set; }
Run Code Online (Sandbox Code Playgroud)
When the instance of services is a ReadOnlyCollection(Resource), the blazor page directly runs into the following error on the client side:
Error: The list of component records is not valid. (blazor.server.js:15)
When the instance of services is a List(Resource), the blazor page works perfectly fine.
To clarify this:
Services = someList.ToList(); // works.
Services = someList.ToList().AsReadOnly(); // does not work
Run Code Online (Sandbox Code Playgroud)
I could not find anything about supported objects passed to Blazor components as parameter in the MSDN documentation. Howevery, I noticed classes without a parameterless constructor seem to be not supported as well. Resource must have a parameterless constructor; otherwise I run into the same error.
Does anyone know the reason here? The object is not used for data binding. It is only used to fill a dropdown list with values. Is this a known Blazor issue in 3.1?
| 归档时间: |
|
| 查看次数: |
678 次 |
| 最近记录: |