I have a simple grid with Add/Edit functionality enabled and it's using the popup grid edit mode. When in that mode, a drop down is not setting the selected value as it should. If I use inline, everything works like a charm.
When the add/edit form is rendered, the selected value for the record is not being set in the drop down. When you submit the form, the value is always correct. The default value is sent when the selected value drop down list was not changed. The same goes for editing (value being the previously saved value).
This behavior seems to only happen on combo boxes and drop down lists and it's limited to the popup form. Below is my view, editor template, and the model. The field in question is Chaperone.
Thank You!
View:
<%= Html.Kendo().Grid<
ChaperoneLogViewModel
>()
.Name("ChaperoneLog")
.DataSource(datasource => datasource.Ajax()
.Read("Select", "ChaperoneLogList")
.Update("Update", "ChaperoneLogList")
.Create("Create", "ChaperoneLogList")
.Destroy("Delete", "ChaperoneLogList")
.Model(model => {
model.Id(field => field.Id);
model.Field(field => field.Name);
model.Field(field => field.Chaperone)
.DefaultValue(HttpContext.Current.User.Identity.Name);
})
.Filter(filter =>
{
filter.Add(field => field.Date)
.IsLessThanOrEqualTo(DateTime.Now)
.And()
.IsGreaterThanOrEqualTo(DateTime.Now.AddDays(-7));
filter.Add(field => field.Chaperone)
.IsEqualTo(HttpContext.Current.User.Identity.Name);
})
.PageSize(20)
)
.EnableCustomBinding(true)
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Excel();
})
.Excel(excel =>
{
excel.AllPages(true);
excel.FileName("ChaperoneList_" + DateTime.Now.ToShortDateString()+".xlsx");
excel.Filterable(true);
})
.Events(events => events.Edit("loadResearch"))
.Columns(columns =>
{
columns.Command(commands =>
{
commands.Destroy().Text(" ");
commands.Edit().Text(" ").CancelText(" ").UpdateText(" ");
}).Width(80);
columns.Bound(column => column.Date).AsDate().Width(90);
columns.Bound(column => column.Name).Title("Topic");
columns.Bound(column => column.Symbol).Title("S").Width(60);
columns.Bound(column => column.BankerListDisp);
columns.Bound(column => column.ResearchListDisp);
columns.Bound(column => column.Other);
columns.Bound(column => column.Chaperone).ClientTemplate("#= ChaperoneDisplay #").Title("C").Width(60);
})
.Pageable()
.Sortable(sort => sort.SortMode(Kendo.Mvc.UI.GridSortMode.SingleColumn))
.Filterable(filter => filter.Mode(GridFilterMode.Menu))
.Scrollable(scroll => scroll.Height("auto"))
.Editable(edit => edit.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
.Selectable()
.Resizable(resizing => resizing.Columns(true))
%>
EditorTemplate:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%
var users = Roles.GetUsersInRole("StandardUser");
var profs = users.Select(WebProfile.GetProfile).ToList();
var list = new List<
SelectListItem
>();
list.AddRange(profs.Select(
x => new SelectListItem
{
Text = String.Format("{1}, {0}", x.FirstName, x.LastName),
Value = Html.Encode(x.UserName)
})
);
list = list.OrderBy(x => x.Text).ToList();
%>
<%=Html.Kendo().DropDownList()
.Name("Chaperone")
.DataValueField("Value")
.DataTextField("Text")
.HtmlAttributes(new {style = "width: 160px; "})
.BindTo(list)
.OptionLabel("Select a Chaperone...")
.Value(Model.ToString())
%>
Model:
namespace CyfPortal.ApplicationServices.ViewModels
{
[DisplayName("Chaperone Log")]
public class ChaperoneLogViewModel : ViewModel<
ChaperoneLog
>
{
public ChaperoneLogViewModel()
{
Chaperone = HttpContext.Current.User.Identity.Name;
}
[ScaffoldColumn(false)]
[Map("Id", ReadOnly = true)]
public int Id { get; set; }
[DataType(DataType.Date)]
public DateTime Date { get; set; }
[UIHint("Symbols")]
public string Symbol { get; set; }
[Display(Name = "Topic")]
public string Name { get; set; }
[UIHint("SeniorBankers")]
public string Banker { get; set; }
public string AddBanker { get; set; }
[UIHint("Analysts")]
public string Research { get; set; }
public string AddResearch { get; set; }
[DataType(DataType.MultilineText)]
public string Other { get; set; }
[UIHint("Chaperone")]
public string Chaperone { get; set; }
public string ChaperoneDisplay
{
get
{
var prof = WebProfile.GetProfile(Chaperone);
var fi = "";
var li = "";
if (!String.IsNullOrEmpty(prof.FirstName)) fi = prof.FirstName.Substring(0, 1);
if (!String.IsNullOrEmpty(prof.LastName)) li = prof.LastName.Substring(0, 1);
return fi+li;
}
}
public string[] ResearchList
{
get
{
if (String.IsNullOrEmpty(Research))
{
return new string[] { };
}
return Research.Split(',');
}
}
[Display(Name = "Research")]
public string ResearchListDisp
{
get
{
if (String.IsNullOrEmpty(AddResearch)) return Research;
return Research + ", " + AddResearch;
}
}
public string[] BankerList
{
get
{
if (String.IsNullOrEmpty(Banker))
{
return new string[] { };
}
return Banker.Split(',');
}
}
[Display(Name = "Banker")]
public string BankerListDisp
{
get
{
if (String.IsNullOrEmpty(AddBanker)) return Banker;
return Banker + ", " + AddBanker;
}
}
}
}