简体   繁体   English

ASP MVC部分视图模型绑定

[英]asp mvc partial view model binding

I've this data model 我有这个数据模型

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

and i'm rendering this form 我正在渲染此表格

@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" />
}

and this is my partial view 这是我的部分观点

@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" })

I want my post edit method to has the object from userinfo instead of null , I'm not sure what i'm missing 我希望我的帖子编辑方法具有来自userinfo的对象,而不是null ,但我不确定我丢失了什么

I've one to one relation between table employee and users info 表员工和用户信息之间存在一对一关系

enter image description here 在此处输入图片说明

The problem is your post method [Bind(Include = "some property")] . 问题是您的post方法[Bind(Include = "some property")] Which means you specified the list of properties only included in the model object, Other properties are not included in the model object. 这意味着您指定了仅包含在模型对象中的属性列表,而其他属性不包含在模型对象中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM