javascript - 模型未从 View 中获取所有属性值(仅新添加的属性)

标签 javascript c# asp.net-mvc razor

这是我的模型

public class Patients
{
    [Key]
    public int PatientId { get; set; }
    [Required]
    public int HospitalId { get; set; }
    public Hospital Hospital { get; set; }

    [Required]
    public string EntryDate { get; set; }

    [Required]
    public string Gender { get; set; }

    [Required]
    public string Age { get; set; }

    [Required]
    [MaxLength(3)]
    [MinLength(1)]
    [RegularExpression("^[0-9]*$", ErrorMessage = "يرجى ادخال الطول بصورة صحيحة")]
    public string height { get; set; }

    [Required]
    public string Ethnicity { get; set; }

    [Required]
    public string Note { get; set; }

    public string Condition { get; set; }

    public string Name { get; set; }

    [Display(Name = "الجنسية")]
    public string Nationality { get; set; }

    public string IDNumber { get; set; }

    public string Status { get; set; }

    public int Patient_ID { get; set; }
    public int Injury_Type { get ; set ; }
    public int Physical_Structure { get; set; }
    public int Skin_Color { get; set; }
    public int Face { get; set; }
    public int Nose { get; set; }
    public int Mouth { get; set; }
    public int Forehead { get; set; }
    public int Eyes { get; set; }
    public int Head_Hair_Color { get; set; }
    public int Pupil_Color { get; set; }
    public int Hair_Type { get; set; }
    public int Hair_Tall { get; set; }
    public int Mustache_Beard { get; set; }
    public int Eyebrows { get; set; }
    public int Ears { get; set; }
    public int Circumcision { get; set; }
    public int Jewelery { get; set; }
    public int Teeth { get; set; }
    public int IndustrialTeeth { get; set; }
    public int Det_ID { get; set; }
}

在 View 中

我试过这个方法

@Html.DropDownListFor(model => model.Injury_Type, ViewBag.lstInjuryType as SelectList, Lang.HomeTexts.SelectInjuryType, htmlAttributes: new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.Injury_Type, "", new { @class = "text-danger" })

这样

@Html.DropDownList("Physical_Structure", ViewBag.lstPysicalStructure as SelectList, Lang.HomeTexts.PhysicalStructure, htmlAttributes: new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.Physical_Structure, "", new { @class = "text-danger" })

我向模型添加了新属性,所有新属性均不采用任何值,仅将 int 设为 0,将字符串设为 null,旧属性照常保留,从 View 中获取正确的值。

提前致谢

最佳答案

你必须尝试, “公共(public)字符串 Injury_Type { 获取 ; 设置 ; }”, “公共(public)字符串Physical_Structure {获取;设置;}”

关于javascript - 模型未从 View 中获取所有属性值(仅新添加的属性),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59205720/

相关文章:

asp.net-mvc - asp .net mvc 授权

javascript - 如何正确记录 require module.exports 以便文档不丢失?

c# - BindAttribute 如何将数据库列绑定(bind)到程序中?

javascript - Angular 2在ngFor中显示/隐藏偶数/奇数项目的换行标签

c# - 如何使用 c#.net 读取 XML 中的 XML 节点

c# - 将两列绑定(bind)到下拉列表中

c# - 取 'First'空格字符前后的字符串

c# - 如何将细节模型从 Controller 传递到 View

javascript - html 和 JavaScript : multiple checkboxes run same function for multiple textboxes

javascript - jwplayer 从另一个域流式传输 m3u