You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Blazor表单@bind-Value始终返回null,请求技术排查与解答

Blazor @bind-Value 返回null问题排查与解决

核心问题1:Title字段未使用双向绑定

你的代码里,Title对应的InputText用了value="employee.Title"而非双向绑定指令,这只会把初始值渲染到输入框,但用户输入的内容不会回写到employee.Title中,提交时该字段自然是null。

核心问题2:绑定指令大小写敏感

Blazor的双向绑定指令严格区分大小写,必须写@bind-Value(V大写),写@bind-value会报错,因为框架不识别这个指令。

修改后的关键代码片段

<div class="form-floating mb-3">
    <InputText @bind-Value="employee.Title" class="form-control" placeholder="Title" />
    <label for="Title">Title</label>
</div>

额外检查点

确保你的Employee类属性是公共且具备get/set访问器,示例如下:

public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int? Age { get; set; }
    public string Title { get; set; }
    public string Gender { get; set; }
}

如果属性是私有或仅包含getter,双向绑定无法更新属性值,同样会导致null。

内容的提问来源于stack exchange,提问作者Gweam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 00:26:16