Telerik Forums
UI for ASP.NET MVC Forum
1 answer
361 views
Hi,

I have followed this example to implement server side validation in my grid edit:

http://www.kendoui.com/code-library/mvc/grid/handling-server-side-validation-errors-during-pop-up-editing.aspx

It works when I used the standard pop up editor but when I substitute it with my custom template editor the tool tip with the model error does not display.

How can I modify this to work with a custom template ? ie one that sits in sharedviews\editor templates\

Vladimir Iliev
Telerik team
 answered on 24 Jan 2013
2 answers
1.2K+ views
@model System.Collections.IEnumerable
 
  
 
@(Html.Kendo().Grid<HoghoughModel.PTStbKarkonan>()
    .Name("Grid")
    .EnableCustomBinding(true)
    .BindTo(Model)
    .Columns(columns => {
        columns.Bound(o => o.IssuePlace);
        columns.Bound(o => o.BimehName);
        columns.Bound(o => o.Family);
        columns.Bound(o => o.Name);
    })
    .Pageable()
    .Sortable()
    .Filterable()
    .Scrollable()
    .Groupable()
    .DataSource(dataSource => dataSource.Server().Total((int)ViewData["total"]))
)
and this code for populating grid :
    public ActionResult Index([DataSourceRequest(Prefix = "Grid")] DataSourceRequest request)
    {
        if (request.PageSize == 0)
        {
            request.PageSize = 10;
        }
 
        IQueryable<PTStbKarkonan> karkonan = db.PTStbKarkonans;
 
        karkonan = karkonan.ApplyFiltering(request.Filters);
 
        var total = karkonan.Count();
 
        karkonan = karkonan.ApplySorting(request.Groups, request.Sorts);
 
        karkonan = karkonan.ApplyPaging(request.Page, request.PageSize);
 
        IEnumerable data = karkonan.ApplyGrouping(request.Groups);
 
        ViewData["total"] = total;
 
        return View(data);
    }
 
public static class PTStbKarkonanExtensions
{
    public static IQueryable<PTStbKarkonan> ApplyPaging(this IQueryable<PTStbKarkonan> data, int page, int pageSize)
    {
        if (pageSize > 0 && page > 0)
        {
            data = data.Skip((page - 1) * pageSize);
        }
 
        data = data.Take(pageSize);
 
        return data;
    }
 
    public static IEnumerable ApplyGrouping(this IQueryable<PTStbKarkonan> data, IList<GroupDescriptor>
        groupDescriptors)
    {
        if (groupDescriptors != null && groupDescriptors.Any())
        {
            Func<IEnumerable<PTStbKarkonan>, IEnumerable<AggregateFunctionsGroup>> selector = null;
            foreach (var group in groupDescriptors.Reverse())
            {
                if (selector == null)
                {
                    if (group.Member == "IssuePlace")
                    {
                        selector = Orders => BuildInnerGroup(Orders, o => o.IssuePlace);
                    }
                    else if (group.Member == "BimehName")
                    {
                        selector = Orders => BuildInnerGroup(Orders, o => o.BimehName);
                    }
                    else if (group.Member == "Family")
                    {
                        selector = Orders => BuildInnerGroup(Orders, o => o.Family);
                    }
                    else if (group.Member == "Name")
                    {
                        selector = Orders => BuildInnerGroup(Orders, o => o.Name);
                    }
                }
                else
                {
                    if (group.Member == "IssuePlace")
                    {
                        selector = BuildGroup(o => o.IDSeri, selector);
                    }
                    else if (group.Member == "BimehName")
                    {
                        selector = BuildGroup(o => o.BimehName, selector);
                    }
                    else if (group.Member == "Family")
                    {
                        selector = BuildGroup(o => o.Family, selector);
                    }
                    else if (group.Member == "Name")
                    {
                        selector = BuildGroup(o => o.Name, selector);
                    }
                }
            }
 
            return selector.Invoke(data).ToList();
        }
 
        return data;
    }
 
    private static Func<IEnumerable<PTStbKarkonan>, IEnumerable<AggregateFunctionsGroup>>
        BuildGroup<T>(Expression<Func<PTStbKarkonan, T>> groupSelector, Func<IEnumerable<PTStbKarkonan>,
        IEnumerable<AggregateFunctionsGroup>> selectorBuilder)
    {
        var tempSelector = selectorBuilder;
        return g => g.GroupBy(groupSelector.Compile())
                     .Select(c => new AggregateFunctionsGroup
                     {
                         Key = c.Key,
                         HasSubgroups = true,
                         Member = groupSelector.MemberWithoutInstance(),
                         Items = tempSelector.Invoke(c).ToList()
                     });
    }
 
    private static IEnumerable<AggregateFunctionsGroup> BuildInnerGroup<T>(IEnumerable<PTStbKarkonan>
        group, Expression<Func<PTStbKarkonan, T>> groupSelector)
    {
        return group.GroupBy(groupSelector.Compile())
                .Select(i => new AggregateFunctionsGroup
                {
                    Key = i.Key,
                    Member = groupSelector.MemberWithoutInstance(),
                    Items = i.ToList()
                });
    }
    public static IQueryable<PTStbKarkonan> ApplySorting(this IQueryable<PTStbKarkonan> data,
                IList<GroupDescriptor> groupDescriptors, IList<SortDescriptor> sortDescriptors)
    {
        if (groupDescriptors != null && groupDescriptors.Any())
        {
            foreach (var groupDescriptor in groupDescriptors.Reverse())
            {
                data = AddSortExpression(data, groupDescriptor.SortDirection, groupDescriptor.Member);
            }
        }
 
        if (sortDescriptors != null && sortDescriptors.Any())
        {
            foreach (SortDescriptor sortDescriptor in sortDescriptors)
            {
                data = AddSortExpression(data, sortDescriptor.SortDirection, sortDescriptor.Member);
            }
        }
 
        return data;
    }
 
    private static IQueryable<PTStbKarkonan> AddSortExpression(IQueryable<PTStbKarkonan> data, ListSortDirection
                sortDirection, string memberName)
    {
        if (sortDirection == ListSortDirection.Ascending)
        {
            switch (memberName)
            {
                case "IssuePlace":
                    data = data.OrderBy(order => order.IssuePlace);
                    break;
                case "BimehName":
                    data = data.OrderBy(order => order.BimehName);
                    break;
                case "Family":
                    data = data.OrderBy(order => order.Family);
                    break;
                case "Name":
                    data = data.OrderBy(order => order.Name);
                    break;
            }
        }
        else
        {
            switch (memberName)
            {
                case "IssuePlace":
                    data = data.OrderByDescending(order => order.IssuePlace);
                    break;
                case "BimehName":
                    data = data.OrderByDescending(order => order.BimehName);
                    break;
                case "Family":
                    data = data.OrderByDescending(order => order.Family);
                    break;
                case "Name":
                    data = data.OrderByDescending(order => order.Name);
                    break;
            }
        }
        return data;
    }
 
    public static IQueryable<PTStbKarkonan> ApplyFiltering(this IQueryable<PTStbKarkonan> data,
        IList<IFilterDescriptor> filterDescriptors)
    {
        if (filterDescriptors != null && filterDescriptors.Any())
        {
            data = data.Where(ExpressionBuilder.Expression<PTStbKarkonan>(filterDescriptors));
        }
        return data;
    }
}
I use EntityFramework. When I run project I get 
System.NotSupportedException: The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'
Atanas Korchev
Telerik team
 answered on 24 Jan 2013
1 answer
78 views
I set up a value of input text box via javascript. However, the value is not seen from server (i.e. remaining as null).

Could anyone advice how to resolve this?
Atanas Korchev
Telerik team
 answered on 24 Jan 2013
3 answers
1.2K+ views
I've created the following editable grid bound to a model. The Date and Integer EditorTemplates work just fine.

However, our user case requires that we multi-select via a checkbox, which is why I added a Selected boolean in the Model. I'd rather cycle through these via the grid's data than by iterating through [tr]s, as it is a much cleaner way to do so.

Via a custom Checkbox EditorTemplate and the ClientTemplate I'm able to successfully display a checkbox. However, I have tried many ways to bind it to the actual Model property and have failed each time. I've tried @HTML.CheckboxFor and @HTML.Checkbox within my EditorTemplate, the latter working properly but not binding to the Model. The CheckboxFor throws a message about not being able to bind a null value... I've tried bool?, bool and System.Boolean, but all three would not bind properly.

View
@(Html.Kendo().Grid(Model.ExtensionDetails)
          .Name("ExtensionInfoGrid")
          .Columns(columns =>
                       {
                           columns.Bound(o => o.Selected)
                                .Title("")
                                .Width(50)
                                .ClientTemplate("<input type='checkbox' id='isSelected' name='isSelected' #if(Selected){#checked#}# value='#=Selected#' />")
                                .EditorTemplateName("Checkbox");
                           columns.Bound(o => o.ExtendFromDate)
                                .Title("Extend From Date *")
                                .Width(150)
                                .Format("{0:M/d/yyyy}")
                                .Filterable(false)
                                .Sortable(true)
                                .EditorTemplateName("Date");
                           columns.Bound(o => o.Units)
                                .Title("Units *")
                                .Width(100)
                                .EditorTemplateName("Integer");
                           columns.Bound(o => o.UnitType).Title("Unit Type");
                       })
          .Editable(editable => editable.Mode(GridEditMode.InCell))
          .DataSource(dataSource => dataSource
                                .Ajax()
                                .ServerOperation(false)
                                .Model(model =>
                                            {
                                                model.Id(m => m.Code);
                                                model.Field(m => m.Selected).Editable(true);
                                                model.Field(m => m.ExtendFromDate).Editable(true).DefaultValue(DateTime.Now);
                                                model.Field(m => m.Units).Editable(true);
                                                model.Field(m => m.UnitType).Editable(false);
                                            })
          )
)}
Model

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ProviderWebAppMVC.UmServiceRef;
 
namespace ProviderWebAppMVC.Models
{
    public class ExtensionDetail
    {
        public ExtensionDetail()
        {
            Selected = true;
            Code = string.Empty;
            Description = string.Empty;
            ExtendFromDate = DateTime.Now;
            ExtendToDate = DateTime.Now;
            Units = 0;
            UnitType = string.Empty;
        }
 
        public bool Selected;
        public string Code;
        public string Description;
        public DateTime ExtendFromDate;
        public DateTime ExtendToDate;
        public int Units { get; set; }
        public string UnitType { get; set; }
    }
}

Vladimir Iliev
Telerik team
 answered on 24 Jan 2013
1 answer
168 views
I am able to define autocomplete in grid popup editor and is also able to select value from the dropdown. However when clicking the update button, the selected value is not retrieved (i.e. value is null).

Any one can advise what happens?
Georgi Krustev
Telerik team
 answered on 24 Jan 2013
1 answer
191 views
I try to use this feature on Dropdownlist but unsuccessful. Any one can provide me a working example besides casading demo one.
Georgi Krustev
Telerik team
 answered on 24 Jan 2013
1 answer
120 views
Hello,
if i have in razor this dropdownlist
@(Html.Kendo().DropDownList()
          .Name("category")
          .OptionLabel("Select a product...")
          .DataTextField("ProductName")
          .DataValueField("ProductID")
          .HtmlAttributes(new { style = "width:200px" })
          .DataSource(source => source.Read("ProductListData", "Controls"))
          .Events(ev => ev.Change("change"))
      
                                        
)

how can i use in the same view, the value of the dropdownlist using razor syntax?
i was looking for something like @Html.Kendo().DropDownList("category").Value()...

Regards,
Daniel

P.S:i think i put first this same post also to Web UI\DropDownList,please excuse me.
Petur Subev
Telerik team
 answered on 24 Jan 2013
4 answers
197 views
Hello,

I have a problem with select tag in latest version of Kendo UI (asp.net MVC Q3 2012).

The options could not be selected if I put select options in a model popup

My select options content:
<select name="country" id="country">
  <option value="AU">AU</option>
  <option value="US">US</option>
  <option value="CN">CN</option>
</select>
It was worked in previous version.

Thanks
 
Justin
Top achievements
Rank 1
 answered on 23 Jan 2013
9 answers
1.2K+ views
I am trying to use a NumericTextBox with a nullable decimal. When the numeric text box is left blank, the default "The field <field name> must be a number" message appears.

How can I submit the data with an empty NumericTextBox to pass a null value to my controller?

Thanks!
Jon
Top achievements
Rank 1
 answered on 23 Jan 2013
2 answers
348 views
Currently the grid edit/delete is showing a button with text along with the mouse over effect, what is the best way to replace these button with an images?  The reason is we see that these button takes too much space and would like to replace it with a smaller image so more data can be shown.  TIA.
Sang
Top achievements
Rank 1
 answered on 23 Jan 2013
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
ComboBox
Upload
MultiSelect
ListView
Window
TabStrip
Menu
Installer and VS Extensions
Spreadsheet
AutoComplete
TreeList
Gantt
PanelBar
NumericTextBox
Filter
ToolTip
Map
Diagram
Button
PivotGrid
Form
ListBox
Splitter
Application
FileManager
Sortable
Calendar
View
MaskedTextBox
PDFViewer
TextBox
Toolbar
Dialog
MultiColumnComboBox
DropDownTree
Checkbox
Slider
Switch
Notification
Accessibility
ListView (Mobile)
Pager
Security
ColorPicker
DateRangePicker
Wizard
Styling
Chat
DateInput
MediaPlayer
TileLayout
Drawer
SplitView
Template
Barcode
ButtonGroup (Mobile)
Drawer (Mobile)
ImageEditor
RadioGroup
Sparkline
Stepper
TabStrip (Mobile)
GridLayout
Badge
LinearGauge
ModalView
ResponsivePanel
TextArea
Breadcrumb
ExpansionPanel
Licensing
Rating
ScrollView
ButtonGroup
CheckBoxGroup
NavBar
ProgressBar
QRCode
RadioButton
Scroller
Timeline
TreeMap
TaskBoard
OrgChart
Captcha
ActionSheet
Signature
DateTimePicker
AppBar
BottomNavigation
Card
FloatingActionButton
Localization
MultiViewCalendar
PopOver (Mobile)
Ripple
ScrollView (Mobile)
Switch (Mobile)
PivotGridV2
FlatColorPicker
ColorPalette
DropDownButton
AIPrompt
PropertyGrid
ActionSheet (Mobile)
BulletGraph
Button (Mobile)
Collapsible
Loader
CircularGauge
SkeletonContainer
Popover
HeatMap
Avatar
ColorGradient
CircularProgressBar
SplitButton
StackLayout
TimeDurationPicker
Chip
ChipList
DockManager
ToggleButton
Sankey
OTPInput
ChartWizard
SpeechToTextButton
InlineAIPrompt
TimePicker
StockChart
RadialGauge
ContextMenu
ArcGauge
AICodingAssistant
SmartPasteButton
PromptBox
SegmentedControl
LLM Kit
+? more
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?