如何解决从MVC应用程序中的选择标记中选取未定义的值
这就是我试图以字段形式显示值的方式:
<div class="form-group">
<label >Doctor Name</label>
<select class="custom-select">
<option value="">Select Role</option>
@{
foreach (var d in ViewBag.Doc)
{
<option value="d.DoctorId">@d.FirstName</option>
}
}
</select>
</div>
我正在尝试选择医生的ID并将其存储在患者数据库中,这将是外键。但是,获取的Doctor ID的值始终为“ 0”。
如果我检查元素,则表单上的值正确。
我不明白为什么它会选择零。
解决方法
设置选择名称
participantArray = [];
namePlusSpouseArray = [];
submitParticipant() {
this.participantArray.push(this.participantForm.value);
console.log(this.participantArray)
this.createNamePlusSpouseArray();
}
createNamePlusSpouseArray() {
this.participantArray.forEach(name => {
this.namePlusSpouseArray.push(this.participantArray[name]);
console.log(this.namePlusSpouseArray)
});
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。