I have a multiselect in a form on a pop up window and I finally got the initial value(s) from the model showing when the window opens, but now when there is an initial value, the select list does not work. I click in the field - no list. It shows the list when I click in the field and there is no initial value and my placeholder text is showing. I need help please! I've added code below and attached screen shots.
Here is my code for the multiselect list:
Here is the code for the Models:
Here's the api code to get the list of all roles:
Any help is very much appreciated!
Donna
Here is my code for the multiselect list:
<div class="form-group"> @Html.Label("User Role(s)") @{ (Html.Kendo().MultiSelectFor(model => model.SelectedRoles) .Name("SelectedRoles") .HtmlAttributes(new {style = "width: 400px"}) .Placeholder("Please select role(s)...") .DataTextField("Name") .DataValueField("Id") .DataSource(source => { source.Read(read => { read.Url("/api/gmcmembership/roles").Type(HttpVerbs.Get); }); }) .Value(Model.SelectedRoles) .AutoBind(false) ).Render(); }</div>Here is the code for the Models:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;namespace GMCWebApplication.Areas.admin.Models{ public class UserDetailViewModel { [HiddenInput] public string Id { get; set; } public int CompanyCode { get; set; } public string UserType { get; set; } public int Question1 { get; set; } public int Question2 { get; set; } public string Question1Answer { get; set; } public string Question2Answer { get; set; }// public string PasswordHash { get; set; } public string PhoneNumber { get; set; } public string NewPassword { get; set; } public List<UserRoleViewModel> SelectedRoles { get; set; } public List<UserRoleViewModel> AllRoles { get; set; } }}using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace GMCWebApplication.Areas.admin.Models{ public class UserRoleViewModel { public string Id { get; set; } public string Name { get; set; } }}Here's the api code to get the list of all roles:
[System.Web.Http.HttpGet][System.Web.Http.Route("roles")]public IHttpActionResult GetRoles(){ try { var list = new List<UserRoleViewModel>(); using (var context = new ApplicationDbContext()) { list = context.Roles.Select(p => new UserRoleViewModel { Id = p.Id, Name = p.Name }) .ToList<UserRoleViewModel>(); } return Ok(list); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return InternalServerError(); }}Any help is very much appreciated!
Donna