1 回答
TA贡献1876条经验 获得超5个赞
像这样试试
视图模型:
public class ApplicationRolesViewModel
{
// Display Attribute will appear in the Html.LabelFor
[Display(Name = "User Role")]
public string RoleId { get; set; }
public IEnumerable<SelectListItem> Roles { get; set; }
}
控制器:
public ActionResult NewRole()
{
var roleData = new IEnumerable<SelectListItem>();
applicationRolesData.GetAllApplicationRoles().Foreach(x =>
roleData.Add( new SelectListItem
{
Value = x.RoleId.ToString(),
Text = x.ApplicationRoleName
});
);
ApplicationRolesViewModel ardlvm = new ApplicationRolesViewModel();
ardlvm.Roles = new SelectList(roleData , "Value", "Text")
return View("~/Views/Users/Modals/AddRole.cshtml", ardlvm);
}
查看:
@model ApplicationRolesViewModel
@Html.LabelFor(m => m.RoleId)
@Html.DropDownListFor(m => m.RoleId, Model.Roles)
并获取当前选择的下拉列表值Jquery:
$('#RoleId').val();
要获取当前选定的文本:
$('#RoleId:selected').text();
- 1 回答
- 0 关注
- 307 浏览
添加回答
举报
