Telerik Forums
UI for ASP.NET MVC Forum
1 answer
218 views
Is it possible to change the format and the input of one grid field column based off another grid field column.  For example, If I had one column field that contains percent, date, string, or number and the other field contains the data (always stored as a string), it is possible to change the display output and editable options of the data based on the other field.  Any examples of this would be greatly appreciated.   Note that the only editable field is the data field but each row could have a different format based off the other field.
Vladimir Iliev
Telerik team
 answered on 21 May 2014
5 answers
165 views
Hello,

i am trying to Display Kendo Editor inside mobile layout. the Editor loads but it is readonly and do not Display any text. It is readonly and i cannot write anything, but clicking on menus seems to work. Fails on Safari ios and also on android and WP 8.

Anamika
Kiril Nikolov
Telerik team
 answered on 20 May 2014
3 answers
636 views
Hello,

I'm using the upload control in async mode and am passing back the empty string to signify success from my post routine.  I need to validate that the file extensions and file size are within certain specs when files are uploaded.  I have seen posts about handling this in jquery and using an alert to display the message but a) I prefer not to use alerts and b) it shows the alert but still goes to the post method (even with the e.preventDefault in place).

I would prefer to do the checks in the post method and return a string that I can display so it would look like my usual validation.  I know that the empty string  signifies success and anything else signifies failure but when I try to trap this in onError it doesn't capture it.  I'm sure there is a way to do this but I am missing something.

Here is my view:
@model PASS.ViewModels.Proposals.AttachmentsViewModel
 
<div class="editor-container">
 
    @Html.Hidden("Form_Disabled", ViewData["FormDisabled"])
 
    <p>File uploads can not exceed 1MB each and must be of the following file types: pdf, jpg, gif, png.</p>
 
    <div class="editor-label">
        @Html.Label("File(s):")
    </div>
    <div class="editor-field">
        @(Html.Kendo().Upload()
            .Name("Upload")
            .Async(async => async
                .Save("AddAttachments", "Proposals", new { proposalID = Model.Proposal_ID })
            )
        )
    </div>
    <br class="clear" />
    <br />
    <br />
 
    @(Html.Kendo().Grid<PASS.ViewModels.Proposals.AttachmentsViewModel>()
        .Name("Attachments")
        .Columns(columns =>
        {
            columns.Bound(c => c.File_Name).ClientTemplate("<a href='" + Url.Action("LoadAttachment", "Proposals") + "/#= ID #'>" + "#= File_Name #" + "</a>").Title("File Name");
            columns.Bound(c => c.File_Size).Title("Size");
            columns.Bound(c => c.Content_Type).Title("Type");
            columns.Command(command => { command.Destroy(); }).Width(90);
        })
        .Sortable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model => model.Id(c => c.ID))
            .Read(read => read.Action("GetAttachments", "Proposals", new { proposalID = Model.Proposal_ID }))
            .Destroy(destroy => destroy.Action("DeleteAttachment", "Proposals"))
        )
    )
 
    <br />
    <p>Upoaded files will not be available for viewing until they have been reviewed.</p>
 
</div>
 
<script type="text/javascript">
$(document).ready(function () {
    var formDisabled = $('#Form_Disabled').val();
    if (formDisabled == "True") {
        $('#Upload').data('kendoUpload').disable();
        $('#Attachments').data('kendoGrid').bind("dataBound", function () {
            $('.k-grid-delete', '#Attachments').hide();
        })
    }
    
    $('#Upload').data('kendoUpload').bind("success", function () {
        $('#Attachments').data('kendoGrid').dataSource.read();
    })
});
</script>


Here is my post method:
[HttpPost]
public ActionResult AddAttachments(int proposalID, IEnumerable<HttpPostedFileBase> upload)
{
    int user_id = Convert.ToInt32(((Claim)((ClaimsIdentity)Thread.CurrentPrincipal.Identity).FindFirst(a => a.Type.Equals("UserID"))).Value);
    var return_message = "";
 
    if (CheckProposalReadAccess(user_id, proposalID))
    {
        using (var context = new PASSEntities())
        {
            foreach (var file in upload)
            {
                if (Path.GetExtension(file.FileName) != ".pdf" || Path.GetExtension(file.FileName) != ".jpg" || Path.GetExtension(file.FileName) != ".gif" || Path.GetExtension(file.FileName) != ".png")
                {
                    return_message = "Uploads must be one of the following file types: pdf, jpg, gif, png.";
                    break;
                }
 
                if (file.ContentLength > 1024)
                {
                    return_message = "Uploads can not be larger than 1MB each.";
                    break;
                }
 
                Proposal_Attachments model = new Proposal_Attachments()
                {
                    Proposal_ID = proposalID,
                    Upload_Date = DateTime.Now,
                    File_Name = Path.GetFileName(file.FileName),
                    File_Size = file.ContentLength,
                    Content_Type = file.ContentType,
                    File_Contents = new byte[file.ContentLength],
                };
 
                file.InputStream.Read(model.File_Contents, 0, file.ContentLength);
 
                context.Proposal_Attachments.Add(model);
                context.SaveChanges();
            }
 
            return Content(return_message);
        }
    }
    else
    {
        return RedirectToAction("Index");
    }
}


Thanks!
Dimiter Madjarov
Telerik team
 answered on 20 May 2014
1 answer
73 views
This code works properly in IE8+, but in IE7 it uploads the file twice:

@(Html.Kendo().Upload()
    .Name("uploadFile")
    .Multiple(false)
    .Async(save => save
                              .Save("DoSomething", "SomeController", new { ... })
                              .AutoUpload(true))
      .Events(events => events 
                  .Upload("...")
                  .Success("...")
                  .Error("..."))
)

I also can't disable the upload widget via this command because $("#uploadFile").data("kendoUpload") returns undefined:
     $("#uploadFile").data("kendoUpload").disable();

My Kendo.Mvc version is v4.0.30319.

Any ideas?
Thanks!
--Berry
Dimiter Madjarov
Telerik team
 answered on 20 May 2014
3 answers
1.0K+ views
Hi,

I'm working on a user management system in asp.net mvc, where I display all my users in a grid using KendoUI. However, I have a string based list of user roles, which I need to display as a dropdown in my edit view. Since my view is generated based on my model, I'm not really sure how to accomplish this.

Here's how my model looks like:
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;
            }
        }
    }
}

Here's my grid:
@(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"))
        )
    )

I don't really need to display the column with selected roles in the grid, but what I do need is the possibility to add / edit them from the popup. Preferably as a multiselect list, as a user could have several roles. I've tried following this example, but can't seem to manage to get it right.
See the attached images for a description of how it looks now.

Vladimir Iliev
Telerik team
 answered on 20 May 2014
1 answer
769 views
I'm working on an application which I have now almost finished but I have one thing that I really need to sort out before I release. I return a dataset of around 600 rows to the grid. I then chose to Edit one of these rows and change the value in a ComboBox Editor template. For example, I might change it from Jan Jones to John Smith.

This all works fine at the database level. However, when I press Update the values displayed in the Display template are still Jan Jones and not John Smith. So far, the only way I've been able to get this to work is by using a dataSource refresh in the onSync event. However, this is taking at least 15 seconds to reload the entire grid.I guess it is returning the entire dataset and not just the currently displayed page.  

Presumably, I am doing something wrong somewhere but I am not sure where. Any help would be most useful as I have been scratching my head on this for a while now.

Controller
01.public JsonResult GetTestDetailed([DataSourceRequest] DataSourceRequest request)
02.{
03.                var testTable = dataAccessLayer.GetDataTable("select statement here");
                          //testTable will be about 600 rows
04.                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.        }


Grid

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 pageing
16.    .Scrollable(scr=>scr.Height("auto"))
17.    .Sortable() // Enable sorting
18.    .DataSource(dataSource => dataSource
19.            .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)))

Dropdown
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)))


Rosen
Telerik team
 answered on 20 May 2014
3 answers
2.1K+ views
Hi,

I would like to hide a specific row in a Kendo UI MVC Grid. Can anybody please help me in this.

---Satish
Alexander Popov
Telerik team
 answered on 19 May 2014
5 answers
266 views
I have a grid with ClientTemplate columns which render to buttons for navigating to other MVC pages.  The first column renders to:
<td role="gridcell"><a href="/WebPortal/Patient/GetPatient/500507" class="btn btn-sm">View Patient</a></td>

However, when I add the .Events parameter, then the ClientTemplate columns do not work and render as:
<td>500507</td>

I want to execute a DataBound event but it messes up the columns.  Any ideas?  Code follows:
​
@(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"))
)
Dimiter Madjarov
Telerik team
 answered on 19 May 2014
2 answers
113 views
I was looking around for an example of how to use the grid control has the datasource for the DataViz control. Would like the pie chart to change based on the filtered data shown in the grid. Thanks
Mike
Top achievements
Rank 1
 answered on 19 May 2014
3 answers
295 views
Hi, 
I´m trying to use a treeview with checkboxes for definition User Rights. (2 actions - enabled/disabled right)
How can I to get value (id) from parent node ?

I attached an example what I need.
Alex Gyoshev
Telerik team
 answered on 19 May 2014
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
DropDownButton
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
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
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?