java如何创建一个文本框_如何创建绑定到对象的文本框

我使用Entity Framework为我的类生成我的控制器和视图 .

这就是我所拥有的:

DemandeController.cs (控制器):

public ActionResult Create()

{

Demande model = new Demande();

model.date = DateTime.Now;

model.status = "en cours";

Employe emp = (Employe)Session["currentUser"];

model.Employe = emp;

ViewBag.ServiceID = new SelectList(db.Services, "id", "nom");

ViewBag.EmployeID = new SelectList(db.Employes, "matricule", "nom");

return View(model);

}

Demande - > Create.cshtml (查看)

@Html.LabelFor(model => model.EmployeID, "Employe")

@Html.DropDownList("EmployeID", String.Empty)

@Html.ValidationMessageFor(model => model.EmployeID)

Employe 课程:

public partial class Employe

{

public Employe()

{

this.ActivityLogs = new HashSet();

this.Demandes = new HashSet();

}

public int matricule { get; set; }

public int DepartementID { get; set; }

public string nom { get; set; }

public string prenom { get; set; }

public string telephone { get; set; }

public string adresse { get; set; }

public string fonction { get; set; }

public string username { get; set; }

public string password { get; set; }

public string role { get; set; }

public Nullable isAdmin { get; set; }

public virtual ICollection ActivityLogs { get; set; }

public virtual ICollection Demandes { get; set; }

public virtual Departement Departement { get; set; }

}

Demande 课程:

public partial class Demande

{

public int id { get; set; }

public int EmployeID { get; set; }

public int ServiceID { get; set; }

public Nullable date { get; set; }

public string status { get; set; }

public string details { get; set; }

public virtual Service Service { get; set; }

public virtual Employe Employe { get; set; }

}

默认情况下,因为我有很多员工,视图会生成 dropdownlist ,我必须选择员工姓名 . 这没有问题 .

但是,我正在尝试将 dropdownlist 更改为 textbox ,它将显示当前登录的employees,该对象保存在 session 对象中 .

我尝试了很多东西,例如从Controller中保存模型中的 Employe 对象,就像你在上面的Controller代码中看到的那样,但它不起作用,因为View没有将整个对象保存到我的理解中所以当我提交时,它覆盖 Employe 对象并仅保留name属性 . 它适用于 date 和 status ,因为它们是基本对象,但不适用于 Employe .

我试着向最好的容量解释,我是ASP.NET MVC的新手 . 如果您希望我提供任何进一步的信息,请告诉我 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值