我有这个模型
public string Rol { get; set; }
[Display(Name = "Perfil:")]
[Required(ErrorMessage = "Seleccione un perfil para el usuario")]
public static IEnumerable<SelectListItem> Roles
{
get
{
yield return new SelectListItem { Text = "Administrador", Value = "1" };
yield return new SelectListItem { Text = "Consultor", Value = "2" };
}
}
public int IdProject { get; set; }
public string ProjectDesc { get; set; }
我的控制员:
public ActionResult _Update(string user, string name, string rol)
{
var obj = new AdministracionDto
{
User = user,
Name = name,
Rol = "2"
};
// ViewBag.Roles1 = new SelectList(AdministracionDto.Roles, "Id", "Name");
return PartialView("_Update", obj);
}
局部视图是弹出窗口,用户单击视图的链接“Actualizar”。并显示弹出窗口
@using (Html.BeginForm("Update", "Login", FormMethod.Post, new { style = "register", style = "height: 34px;" } ))
{
<b>@Html.LabelFor(model => model.Name)</b>
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { PlaceHolder = "Ingrese nombre", @required = "required", @class = "input-register", style = "height: 34px;" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
<b>@Html.LabelFor(model => model.Rol)</b>
@Html.DropDownListFor(m => m.Rol, AdministracionDto.Roles, "--Seleccione Perfil", new { @class = "form-control", @required = "required" })
@Html.ValidationMessageFor(model => model.Rol, "", new { @class = "text-danger" })
<button type="button"class="close" data-dismiss="modal">Cancelar</button>
<button type="submit" class="signupbtn" value="Create">Actualizar</button>
}
但我的问题是:当进入actionresult _Update时。我在dropdownlisFor中丢失了所选的值。但我需要在“2。
中建立值