1

我有 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>

所以我的问题是,我不知道如何Dropdownlist使用 RESTful 服务填充我的 AD 中的值。知道怎么做吗?

4

0 回答 0