如何在创建表单时设置当前的UserId?

时间:2014-11-26 17:03:45

标签: c# asp.net-mvc

当我创建一个带有空格的表单来完成时,我在字段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>

0 个答案:

没有答案