我有MVC3项目基于声明的身份验证。
我设法让登录工作。
我现在要做的是用DropDownList
填充组,然后用属于该组的用户填充另一个DropDownlist
。
截至目前,我在DropDownlist
填写了来自我本地数据库的用户。
这是我从某个办公室获取用户的方法
private static void GetUsers(UsersContext.Format wFormat)
{
new UsersContext(new Uri("http://site/api/users"), wFormat)
.Users
.Where(x => x.Office.Equals("HomeOffice"))
.ToList()
.ForEach(
item =>
{
var user = item.DisplayName;
});
}
现在我的控制器如何填充:
public ActionResult Create()
{
var model = new TaskViewModel();
var subjectypes = createNKIRep.GetAllSubjectTypesById();
var customer = createNKIRep.GetAllCustomersByID();
var teams = createNKIRep.GetAllTeamsByID();
var users = createNKIRep.GetAllUsersByID();
model.Teams = new SelectList(teams, "Id", "Name");
model.Users = new SelectList(users, "Id", "Name");
model.SubjectTypes = new SelectList(subjectypes, "Id", "Name");
model.Company = new SelectList(customer, "Id", "CompanyName");
}
return View(model);
这是我填写下拉列表的视图
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<h4>Get users to customer</h4>
<legend></legend>
<p>Subjecttype</p>
<div class="editor-field">
@Html.DropDownListFor(m => m.SubjectTypeName, Model.SubjectTypes, "Subjecttype", new { @class = "selectstyle" })
@Html.ValidationMessageFor(model => model.SubjectTypeName)
</div>
<p>Team</p>
<div class="editor-field">
@Html.DropDownListFor(model => model.TeamName, Model.Teams, "Team", new { @class = "selectstyle"})
@Html.ValidationMessageFor(model => model.TeamName)
</div>
<p>Users</p>
<div class="editor-field">
@Html.DropDownListFor(model => model.UserName, Model.Users, "Users", new { @class = "selectstyle"})
@Html.ValidationMessageFor(model => model.UsersName)
</div>
<p>Customer</p>
<div class="editor-field">
@Html.DropDownListFor(model => model.CompanyName, Model.Company, "Company", new { @class = "selectstyle" })
@Html.ValidationMessageFor(model => model.CompanyName)
</div>
所以我的问题是,我不知道如何用我的AD使用restful服务填充Dropdownlist
的值。知道如何做到这一点吗?