asp mvc 部分视图模型绑定

asp mvc partial view model binding

我有这个数据模型

public partial class UsersInfo
{
    public int UserID { get; set; }
    public string Name_f { get; set; }
    public string Name_l { get; set; }
    public string Photo { get; set; }
    public bool ActiveAccount { get; set; }
}

public partial class Employee
{
    public int EmpID { get; set; }
    public int BranchID { get; set; }
    public virtual UsersInfo UsersInfo { get; set; }
}

我正在呈现此表单

@model LoanApp.Models.DataBaseModel.Employee
@using (Html.BeginForm((string)ViewBag.Contoler, "Employe", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.Partial("~/Views/Shared/_userInfo.cshtml",Model.UsersInfo)
    <label class="control-label">يعمل في فــرع</label>
    @Html.DropDownList("BranchID", null, htmlAttributes: new { @class = "form-control" })
    <input type="submit" value="Save" class="btn btn default" />
}

这是我的部分观点

@model LoanApp.Models.DataBaseModel.UsersInfo
@Html.TextBoxFor(x => x.Name_f, new { @class = "form-control", @placeholder = "الاسم الاول", @required = "" })
@Html.TextBoxFor(x => x.Name_l, new { @class = "form-control", @placeholder = "الاسم الاخير", @required = "" })
@Html.TextBoxFor(x => x.PhoneNumber, new { @class = "form-control", @required = "", @number = "true" })

我希望我的 post 编辑方法具有来自 userinfo 而不是 null 的对象,我不确定我缺少什么

我在 table 员工和用户信息之间建立了一对一关系

enter image description here

问题是您的 post 方法 [Bind(Include = "some property")]。这意味着您指定的属性列表仅包含在模型对象中,其他属性不包含在模型对象中。