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

ASP.NET Core MVC表单提交后模型绑定属性返回Null值问题求助

根因分析

ASP.NET Core MVC 默认的模型绑定逻辑仅支持绑定公共属性,你定义的Form3040VM类中的patient、patientVisit等成员均为公共字段,没有添加属性访问器,因此模型绑定过程会跳过这些成员,导致取值为null。
IFormCollection直接读取原始请求的表单键值对,不依赖模型绑定的属性映射规则,所以可以正常读取到提交的值。

修复方案

将Form3040VM中的公共字段修改为带get/set访问器的公共属性即可,修改后的代码如下:

public class Form3040VM
{
    public tblPatientVisits patientVisit { get; set; } = new tblPatientVisits();
    public tblPtmstr1 patient { get; set; } = new tblPtmstr1();
    public tbl_Log_Vitals patientVitals { get; set; } = new tbl_Log_Vitals();
    public FHSAAFindings findings { get; set; } = new FHSAAFindings();
}

修改后重新编译运行,表单提交的patient.PatientFirstName值就会被正确绑定到入参模型的对应属性上。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 18:45:03