1
db의 모든 역할을 드롭 다운 목록에 표시하려고합니다.이 방법으로 역할 공급자의 GetAllUser 메서드를 재정의했습니다.db에서 dropdownlist로 모든 역할 표시
public string[] GetAllRoles()
{
string[] roles = Session.Query<RoleManager>()
.Select(r => r.roleName)
.ToArray();
return roles;
}
컨트롤러에서이 메서드를 호출했습니다.
[HttpGet]
public ActionResult DisplayAllRoles()
{
string[] allRoles = ((CustomRoleProvider)Roles.Provider).GetAllRoles();
if (allRoles != null)
{
//bind dropDownlist list in view with all roles ???
ModelState.AddModelError("", "List of All roles");
}
else ModelState.AddModelError("","No role exists.");
return View();
}
보기 :
@Html.DropDownListFor(m => m.AllRoles,new SelectList (Model.AllRoles))
지금 내 질문에 내가 roles.Can의 문자열 배열에서 드롭 다운리스트를 채울 수있는 방법은 내 사건에 대한 샘플 코드를 작성하시기 바랍니다 것입니다.
역할 값을 하드 코딩하고 싶지 않습니다. 문자열 배열 allroles에는 dropdownlist를 채울 역할이 있습니다. – Wasfa
물론. 귀하의 예제에서 하드 코딩 된 값은 실제 구현 문자열로 대체됩니다 [] allRoles = ((CustomRoleProvider) Roles.Provider) .GetAllRoles(); 그래서이 줄을 주석 처리했습니다. – Spock
var roleModel의 범위는 if 문 내에 있지만 if 밖에서 returing합니다. 외부에서 액세스 할 수있게 만드는 방법은 다음과 같습니다. – Wasfa