0

回发后,我遇到了引导多选控制的问题。在我看来,有一个下拉菜单

@Html.DropDownListFor(model => model.SelectedReportToRoles, Model.NotificationReportToRoles, new { multiple = "multiple", @class = "select-optional multiselect", @id = "ddlReportTo" })

而且,当我从 ddl 中选择多个项目并将其保存到 DB,然后返回页面时,我只能看到我选择的项目中的第一个项目,仅在 ddl 中显示为已选中。如果我刷新页面,它会根据需要运行。即,ddl 将数据库中的所有项目显示为已选择(如选择了 3 个项目)

我的控制器动作就像

   [HttpGet]
    public ActionResult Create()
    {
        return this.View(this.GenerateViewModel());
    }

    private static NotificationSettingsViewModel GenerateNotificationSettingsViewModel()
    {
        NotificationSettingsViewModel notificationSettingsViewModel = new NotificationSettingsViewModel();

    // Getting the roles from DB and assigning that to int array selectedReportToRoles

    notificationSettingsViewModel.NotificationReportToRoles = new MultiSelectList(roles, "RoleID", "RoleDescription", selectedReportToRoles);
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(NotificationSettingsViewModel notificationSettingsViewModel)
    {
          // Save to Db
          return this.View(this.GenerateViewModel());
    }

我正在使用 jquery 版本 1.8.2

任何帮助表示赞赏。

4

1 回答 1

0

我通过将更改的参数保存到TempData然后从我的 post 操作重定向到 Get 操作解决了这个问题。

return this.RedirectToAction("Create");
于 2015-03-24T10:19:34.687 回答