返回
Amanda

Blazor 路由参数报错 No writer was cached for the property 'MyId' on type 'BlazorApp2.Pages.Index'.

用Blazor碰到了问题,在页面上想接收id参数的值,但是报错了。

InvalidOperationException: No writer was cached for the property 'Id' on type 'BlazorApp2.Pages.Index'.

@page "/{id}"

@code {

[Parameter]

public string? Id { get; set; }

}

报错了。

原来报错InvalidOperationException: Object of type 'BlazorApp2.Pages.Index' has a property matching the name 'id', but it does not have [ParameterAttribute] or [CascadingParameterAttribute] applied. 是因为没有加[Parameter]标签,但是加了报这个新的错,知道是什么原因吗?

回复

PaulYu
PaulYu

是在VS里开发的吗?如果是按F5浏览的可以尝试停止后重新按F5调试。

如果是运行命令dotnet watch运行的,可以Ctrl+C推出后重新运行dotnet watch命令。

总之就是重启再试应该就好了。

回复

回复 楼主
顶部