【问题标题】:Model not taking all properties value from the View(new added Property only)模型未从视图中获取所有属性值(仅限新添加的属性)
【发布时间】:2020-03-31 00:13:00
【问题描述】:

这是我的模特

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; }
}

在视图中

我试过这种方法

@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 设置零,为字符串设置 null 旧属性保持不变,从视图中获取正确的值。

提前致谢

【问题讨论】:

  • 你能在控制器中显示 ViewBag.lstInjuryType 吗?
  • 'ViewData["lstInjuryType"] = new SelectList(service.GetParameters(" and Major = 'InjuryType' and lang ='" + lang + "'").DefaultView, "Minor", " Minor_Text");'
  • 通过在容器 div 中组合 div 找到了解决方案,问题是模型无法从多 div 读取(我不知道为什么)谢谢

标签: javascript c# asp.net-mvc razor


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-07-31
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 2013-12-05
    • 1970-01-01
    • 2021-03-23
    相关资源
    最近更新 更多