我使用身份的身份验证系统。我需要获取ID并将其与ID匹配,因为我需要使用在系统中输入的用户的电子邮件来创建一条记录。
public ActionResult Create()
{
ViewBag.OfPostUsr_ID = new SelectList(db.AspNetUsers, "Id", "Email");
ViewBag.OfPostOf_ID = new SelectList(db.OfertaLaboral, "Of_ID", "Of_Titulo");
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "OfPost_ID,OfPostOf_ID,OfPostUsr_ID,OfPostFecha")] OfertaPostulante ofertaPostulante)
{
if (ModelState.IsValid)
{
db.OfertaPostulante.Add(ofertaPostulante);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.OfPostUsr_ID = new SelectList(db.AspNetUsers, "Id", "Email", ofertaPostulante.OfPostUsr_ID);
ViewBag.OfPostOf_ID = new SelectList(db.OfertaLaboral, "Of_ID", "Of_Titulo", ofertaPostulante.OfPostOf_ID);
return View(ofertaPostulante);
}
要显示的视图是这样的:
<div class="form-horizontal">
<h4>OfertaPostulante</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.OfPostOf_ID, "OfPostOf_ID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("OfPostOf_ID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.OfPostOf_ID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.OfPostUsr_ID, "OfPostUsr_ID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("OfPostUsr_ID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.AspNetUsers.Email, "", new { @class = "text-danger" })
</div>
</div>
我需要ID,用户或电子邮件,默认情况下显示,并且不能在下拉菜单中进行修改(因为我从“ AspNetUsers”和电子邮件中随机获得所有电子邮件)
请,谢谢!