or
public class UserModel{ #region Properties [Display(Name = @"Username")] [Required] public string UserName { get; set; } [Required] public string Name { get; set; } [Display(Name = @"E-mail")] [EmailAddress] public string Email { get; set; } public string Phone { get; set; } public string Company { get; set; } [DataType(DataType.Password)] [Display(Name = @"Password")] [Required] public string PasswordHash { get; set; } [Display(Name= @"Roles")] public List<string> UserRoles { get; set; } [ScaffoldColumn(false)] public string UserRoleIcon { get; set; } [ScaffoldColumn(false)] public string UserRoleIconInverted { get; set; } #endregion public UserModel() { } public UserModel(UserContract userContract) { SetupUserModel(userContract); } private void SetupUserModel(UserContract userContract) { UserName = userContract.UserName; Name = userContract.Name; Email = userContract.Email ?? ""; Phone = userContract.Phone ?? ""; Company = userContract.Company ?? ""; PasswordHash = userContract.PasswordHash ?? ""; UserRoles = new List<string>(); if (userContract.UserRoles != null) { foreach (var userRole in userContract.UserRoles) { UserRoles.Add(userRole); } } SelectUserRoleIcon(UserRoles); } // TODO: Hierarchy on roles and selecting images? private void SelectUserRoleIcon(IEnumerable<string> userRoles) { foreach (var userRole in userRoles) { switch (userRole.ToLower()) { case "administrator": UserRoleIcon = "Administrator.png"; UserRoleIconInverted = "Administrator_Black.png"; break; case "operator": UserRoleIcon = "Operator.png"; UserRoleIconInverted = "Operator_Black.png"; break; case "supervisor": UserRoleIcon = "Supervisor.png"; UserRoleIconInverted = "Supervisor_Black.png"; break; default: UserRoleIcon = "Guest.png"; UserRoleIconInverted = "Guest_Black.png"; break; } } }}@(Html.Kendo().Grid<Stimline.Xplorer.Services.Models.User.UserModel>() .Name("grid") .Columns(columns => { columns.Bound(p => p.UserName); columns.Bound(p => p.Name); columns.Bound(p => p.Email); columns.Bound(p => p.Phone); columns.Bound(p => p.UserRoles); columns.Command(command => { command.Edit(); }).Width(160); }) .ToolBar(toolbar => toolbar.Create()) .Editable(editable => editable.Mode(GridEditMode.PopUp)) .Pageable() .Sortable() .Scrollable() .HtmlAttributes(new { style = "height:430px;" }) .DataSource(dataSource => dataSource .Ajax() .PageSize(20) .Events(events => events.Error("error_handler")) .Model(model => model.Id(p => p.UserName)) .Create(update => update.Action("EditingPopup_Create", "UserManagement")) .Read(read => read.Action("EditingPopup_Read", "UserManagement")) .Update(update => update.Action("EditingPopup_Update", "UserManagement")) //.Destroy(update => update.Action("EditingPopup_Destroy", "Grid")) ) )01.public JsonResult GetTestDetailed([DataSourceRequest] DataSourceRequest request)02.{03. var testTable = dataAccessLayer.GetDataTable("select statement here");
//testTable will be about 600 rows04. var testDictionary = (from DataRow row in testTable.Rows select testTable.Columns.Cast<DataColumn> ().ToDictionary(column => column.ColumnName, column => row[column].ToString())).ToList().AsQueryable();05. return Json(testDictionary.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);06. }07. }08. 09. [AcceptVerbs(HttpVerbs.Post)]10. public ActionResult Update([DataSourceRequest] DataSourceRequest request, TestDirectoryDetail testDetail)11. {12. dataAccessLayer.Update(testDetail);13. return Json(new[] { testDetail }.ToDataSourceResult(request, ModelState));14. }01.<script type="text/javascript">02. function onSync(e) {03. var grid = $('#TestGrid').data('kendoGrid');04. grid.dataSource.read();05. }06.</script>07. 08.@(Html.Kendo().Grid((IEnumerable<DirectoryDetail>)ViewBag.Details)09. .Name("TestGrid")10. .HtmlAttributes(new { style = "height:850px;" })11. .Editable(editable => editable.Mode(GridEditMode.InLine))12. .Events(e => e.SaveChanges("onSaveChanges"))13. .Filterable()14. .Groupable() 15. .Pageable() // Enable pageing16. .Scrollable(scr=>scr.Height("auto"))17. .Sortable() // Enable sorting18. .DataSource(dataSource => dataSource19. .Ajax()20. .Events(events => events.Error("error_handler").Sync("onSync"))21. .PageSize(15)22. .Model(model => 23. {24. model.Id(p => p.Id);25. })26. .Update(update => update.Action("Update", "Home"))27. .Read(read => read.Action("GetPracticesDetailed", "Home"))28. )29. .Columns(columns =>30. {31. columns.Bound(m => m.PracticeId).Title("Id");32. columns.Bound(m => m.PayManager).Width(150).Title("DPM").Template(m => m.PayManager).EditorTemplateName("PayManagerDropDown").ClientTemplate("#:PayManager#");33. columns.Command(command => command.Edit()).Title("Actions");34. }) 35. .Resizable(resize => resize.Columns(true)))01.@(Html.Kendo().ComboBox()02. .Name("PayManagerId")03. .Filter(FilterType.StartsWith)04. .HtmlAttributes(new {style = "width:auto;"})05. .Placeholder("Type beginning of name to select new pay manager")06. .DataTextField("FullName")07. .DataValueField("userid")08. .AutoBind(true)09. .Suggest(true)10. .DataSource(source => source.Read(read => read.Action("GetUsers", "Home")).ServerFiltering(false)))@(Html.Kendo().Grid(Model) .Name("PatientSearchGrid") .Columns(columns => { columns.Bound(e => e.LName).Title("Last Name"); columns.Bound(e => e.FName).Title("First Name"); columns.Bound(e => e.ReferralDate); columns.Bound(e => e.Status); columns.Bound(e => e.ID).Hidden(); columns.Bound(e => e.ID).ClientTemplate( "<a href='" + Url.Action("GetPatient", "Patient") + "/#= ID #'" + "class='btn btn-sm'>View Patient</a>" ).Width(110).Title(""); columns.Bound(e => e.ID).ClientTemplate( "<a href='" + Url.Action("CreateAccount", "Patient") + "/#= ID #'" + "class='btn btn-sm'>Create Account</a>" ).Width(127).Title(""); }) .HtmlAttributes(new { style = "height: 390px;" }) .Pageable(pageable => pageable .PageSizes(true).PageSizes(new int[] { 20, 50, 100 }) .ButtonCount(5)) .Sortable() .Filterable() .Scrollable() .DataSource(dataSource => dataSource .Ajax() .Sort(s => s.Add(n => n.LName)) .PageSize(20) .ServerOperation(false)) //.Events(events => events.DataBound("dataBound")))@(Html.Kendo().DropDownList() .Name("CompanyId") .OptionLabel("Choose company") .BindTo(MMHtmlHelperExtension.SelectListForCompany(Model != null ? Model.CompanyId : null)) .HtmlAttributes(new { data_value_primitive = "true" }) )@(Html.Kendo().DropDownList() .Name("DepartmentId") .OptionLabel("Choose department") //We would like to remove this, but if this is removed and the dropdown contains only one element that element cannot be selected .DataSource(source => source .Read(read => read.Action("GetDepartmentsInCompany", "EditorTemplates", new {area = ""})) .ServerFiltering(true)) .Enable(false) .AutoBind(false) .CascadeFrom("CompanyId") .HtmlAttributes(new { data_value_primitive = "true" }) )
<input id="inputToIllustrateMVVMBehaviour" data-bind="value: DepartmentId" />departmentDropDownList .dataSource .bind("change", function(e) { if (departmentDropDownList.select() == 0) { departmentDropDownList.select(1); //Visibly changes the dropdown, but does not update the MVVM value $("#DepartmentId_listbox").children().eq(1).click(); //Extremely hacky workaround that actually works. Selecting a department manually by clicking also works. } });SO - the main questions:
Best regards
Victor
[HttpGet]public PartialViewResult GetSearchPartialView(string projectName){ RawrSearchAreaModel model = new RawrSearchAreaModel(); // get a list of all window dates from DB List<DateTime> RunDates; using (RAWREntities dbcontext = new RAWREntities()) { RunDates = dbcontext.Messages.Where(m => m.ProjectName == projectName).Select(x => x.RunDateTime).Distinct().ToList(); } JavaScriptSerializer jss = new JavaScriptSerializer(); model.ScheduledDatesJson = jss.Serialize(RunDates.Select(x => x.ToShortDateString()).ToArray()); return PartialView("_rawrSearchArea", model);}@(Html.Kendo().DatePicker() .Name("startDatePicker") .Events(events => { events.Change("startDateChanged"); } ) .MonthTemplate("#if ( $.inArray(kendo.toString(new Date(+data.date), 'M/d/yyyy'), " + @Model.ScheduledDatesJson + ") != -1) {#" + "<div class='dateHasWindows'>" + "#}else {#" + "<div>" + "#}#" + "#= data.value #" + "</div>" ) )@(Html.Kendo().DatePicker() .Name("startDatePicker") .Events(events => { events.Change("startDateChanged"); } ) .MonthTemplateId("calendarTemplate") )<script id="calendarTemplate" type="text/x-kendo-template"> #if ( $.inArray(kendo.toString(new Date(+data.date), 'M/d/yyyy'), " + @Model.ScheduledDatesJson + ") != -1) {# <div class='dateHasWindows'> #}else {# <div> #}# #= data.value # </div></script>