当我创建一个带有空格的表单来完成时,我在字段UserId上有一个选择列表,如何自动选择经过身份验证的用户???
控制器:
public ActionResult Create()
{
ViewBag.UserId = new SelectList(db.Users, "UserId", "FullName");
return View();
}
查看创建:
<div class="form-group">
@Html.LabelFor(model => model.UserId, "UserId", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("UserId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.UserId, "", new { @class = "text-danger" })
</div>
</div>