Telerik Forums
UI for ASP.NET MVC Forum
1 answer
1.2K+ views

Hi, 

I need to display data in grid where it needs to display pre uploaded files in one of the column. User will also be able to edit the column and be able to delete or upload new attachment in the column. The user should be able to upload multiple files and the grid should display multiple files if the user has already uploaded previously. 

I have been able to display data in grid with one attachment but having hard time to figure out how to display multiple files and enable uploading multiple files in the grid.

Here is my code:

Razor View:
Test.cshtml

@using Kendo.Mvc.UI
 
@{
    ViewBag.Title = "Test";
}
 
<h2>Test</h2>
<input id="btnSearch" type="button" value="Search" class="btn btn-default icon-btn-input" />
 
<div class="col-sm-12">
    @(Html.Kendo().Grid<KendoUIApp3.Models.Certification>()
          .Name("Grid1")
          .Columns(columns =>
          {
              columns.Bound(e => e.SupplierNumber).Width("170px");
              columns.Bound(e => e.CustomerItemNumber).Width("170px");
          })
          .Editable(editable => editable.Mode(GridEditMode.InLine))
          .Pageable(x => x.PageSizes(new object[] { 10, 20, 50, 100, "All" }))
          .Reorderable(reorder => reorder.Columns(true))
          .AutoBind(false)
          .Selectable()
          .Sortable(sortable => sortable
              .AllowUnsort(true)
              .SortMode(GridSortMode.MultipleColumn))
          .Scrollable(scr => scr.Height(322))
          .Filterable(filterable => filterable
              .Extra(false)
              .Operators(operators => operators
                  .ForString(str => str.Clear()
                      .Contains("Contains")
                      .StartsWith("Starts with")
                      .IsEqualTo("Is equal to")
                      .IsNotEqualTo("Is not equal to"))))
          .Resizable(resize => resize.Columns(true))
          .DataSource(dataSource => dataSource
              .Ajax()
              .PageSize(10)
              .ServerOperation(false)
              .Read(read => read.Action("GetTestData", "Home"))
              .Model(model =>
              {
                  model.Id(p => p.SupplierNumber);
              }))
              .Events(events => events.Change("onRowSelect"))
          )
</div>
<br/><br/>
 
 
<div class="col-sm-12">
    @(Html.Kendo().Grid<KendoUIApp3.Models.CertificationDetail>()
          .Name("Grid2")
          .Columns(columns =>
          {
              columns.Command(command =>
              {
                  command.Edit().Text("Edit").HtmlAttributes(new { title = "Edit" });
              }).Width(180).Title("Action");
              columns.Bound(e => e.CertificationName).Width("170px");
              columns.Bound(e => e.Value).ClientTemplate("<input type='checkbox' disabled #=Value == true ? checked='checked' : '' # />").Width("170px");
              columns.Bound(e => e.Attachment).Width("300px").ClientTemplate("#if (Attachment != null && Attachment != '')" +
                                                                                            "{# <a href='#=Attachment#' target='_blank' class='btn-success'>View Attachment</a> #}#")
                                                                                            .EditorTemplateName("_UploadAttachment");
          })
          .Editable(editable => editable.Mode(GridEditMode.InLine))
          .Pageable(x => x.PageSizes(new object[] { 10, 20, 50, 100, "All" }))
          .Reorderable(reorder => reorder.Columns(true))
          .AutoBind(false)
          .Selectable()
          .Sortable(sortable => sortable
              .AllowUnsort(true)
              .SortMode(GridSortMode.MultipleColumn))
          .Scrollable(scr => scr.Height(322))
          .Filterable(filterable => filterable
              .Extra(false)
              .Operators(operators => operators
                  .ForString(str => str.Clear()
                      .Contains("Contains")
                      .StartsWith("Starts with")
                      .IsEqualTo("Is equal to")
                      .IsNotEqualTo("Is not equal to"))))
          .Resizable(resize => resize.Columns(true))
          .DataSource(dataSource => dataSource
              .Ajax()
              .PageSize(10)
              .ServerOperation(false)
              .Read(read => read.Action("GetDetailTestData", "Home").Data("selectedRow"))
              .Model(model =>
              {
                  model.Id(p => p.CertificationName);
              })
              .Update(update => update.Action("SaveCertificationDetail", "Home")))
    )
</div>
 
<script>
    $('#btnSearch').click(function(e) {
        $('#Grid1').data('kendoGrid').dataSource.read();
    });
 
    function selectedRow() {
        var grid = $("#Grid1").data("kendoGrid");
        var selectedItem = grid.dataItem(grid.select());
        var data = selectedItem ? selectedItem.toJSON() : {};
 
        return { model: data }
    }
 
    function onRowSelect() {
        $('#Grid2').data('kendoGrid').dataSource.read();
    }
</script>

_UploadAttachment.cshtml

@using Kendo.Mvc.UI
 
@(Html.Kendo().Upload()
        .Name("uploadedFiles")
        .Messages(m => m.Select("Upload Attachment"))
        .Async(a => a
                .Save("SaveAttachments", "Home")
                .Remove("RemoveAttachments", "Home")
            .AutoUpload(true)
        )
        .Multiple(false)
        //.Events(e => e.Success("onUploadSuccess"))
        //.Events(e => e.Upload("function(args){checkFileExtension(args,'.pdf');}"))
        .HtmlAttributes(new { accept = ".pdf" })
)

HomeController.cs

public ActionResult Test()
{
    return View();
}
 
public JsonResult GetTestData([DataSourceRequest] DataSourceRequest request)
{
    var certificationList = new List<Certification>();
    certificationList.Add(new Certification {SupplierNumber = "4343", CustomerItemNumber = "123344"});
    certificationList.Add(new Certification {SupplierNumber = "4242", CustomerItemNumber = "23453"});
    return Json(certificationList.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
 
public JsonResult GetDetailTestData([DataSourceRequest] DataSourceRequest request, Certification model)
{
    var certificationDetailLists = new List<CertificationDetail>();
 
    if (model.SupplierNumber == "4343")
    {
        certificationDetailLists.Add(new CertificationDetail {CertificationName = "ROHS", Value = true, Attachment = "Test.pdf"});
        certificationDetailLists.Add(new CertificationDetail {CertificationName = "REACH", Value = false});
    }
    else
    {
        certificationDetailLists.Add(new CertificationDetail { CertificationName = "RLIM", Value = false });
        certificationDetailLists.Add(new CertificationDetail { CertificationName = "RETIM", Value = true });
    }
    return Json(certificationDetailLists.ToDataSourceResult(request));
}
 
public ActionResult SaveAttachments(IEnumerable<HttpPostedFileBase> uploadedFiles)
{
    return Json(null);
}
 
public ActionResult RemoveAttachments(string[] fileNames)
{
    return Json("");
}

 

Model:

public class Certification
{
    public string SupplierNumber      { get; set; }
    public string CustomerItemNumber  { get; set; }
}
 
public class CertificationDetail
{
    public string CertificationName { get; set; }
    public bool Value               { get; set; }
    public string Attachment        { get; set; }
}

Danail Vasilev
Telerik team
 answered on 30 Aug 2016
1 answer
309 views

So I'm using 2016.1.412 Telerik controls.  MVC Grid UI.

 

I've followed this (http://www.telerik.com/support/code-library/checkbox-column-and-incell-editing) in order to get one of my boolean? columns to only show a checkbox and allow single click changes.  It works if I very carefully click on the check box.  If I click (within the cell) but next to the check box I get the drop list with the values "true, false, not set".  How do I get rid of the drop list?

 

1.columns.Bound(p => p.SendTo).Template(@<text></text>).ClientTemplate("<input type='checkbox' #= SendTo ? checked='checked':'' # class='sendtochkbx'/>")
2.  .Title(GridColumns.SendToPorzio)
3.  .Filterable(true)
4.  .HtmlAttributes(new { style = "text-align: center;" })
5.  .Sortable(false)
6.  .Width(150)
7.  .Locked(true)
8.  .HeaderTemplate("Send To Porzio <input type='checkbox' id='masterCheckBox' onclick='checkAll(this)'/>   ");

1.$("#SpendGrid").on('click',
2.    '.sendtochkbx',
3.    function () {
4.        var checked = $(this).is(':checked');
5.        var dataItem = grid.dataItem($(this).closest('tr'));  //grid is defined earlier in code block
6.        dataItem.set('SendTo', checked);
7.    });

Viktor Tachev
Telerik team
 answered on 30 Aug 2016
1 answer
128 views

How can I style my web application to have a consistent look and feel?

Most places I used the kendo controls (Kendo helpers) however there are some places in my application where I've had to use the standard html helpers or just the regular markup.

In those cases I would the appearance of the Kendo style. (Checkboxes, textboxes, etc).

How can I accomplish this?

Vessy
Telerik team
 answered on 29 Aug 2016
3 answers
658 views

Hi,

I have a where i need to display data and have a button in each row, on click of the button need to toggle the record with selected property as 0 or 1.

I have used a custom command as i do not need to edit the records. and have used a click on the command, below is the code in the javascript method called in the click. But this makes the row editable and then updates the record but there is no post done to the controller, i have set the Update and Create event both. Please can you help and let me know if this is the current way of doing it.

columns.Command(command =>
{
   command.Custom("Set").Click("onSetActive").HtmlAttributes(new { @className = "k-icon k-update",   @title = "Set" });
   command.Custom("Unset").Click("onUnsetActive").HtmlAttributes(new { @className = "k-icon k-cancel", @title = "Unset" });
}).Width(145);

......

.Create(update => update.Action("Update", "My"))
 .Read(read => read.Action("Read", "My"))
.Update(update => update.Action("Update", "My"))
 
function onSetActive(e)
{
        e.preventDefault();
        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
        var row = $(e.currentTarget).closest("tr");
        var grid = $("#Grid").data("kendoGrid");
        grid.editRow(row);
        dataItem.Selected = 1;
        setTimeout(function () {
            grid.saveRow();
        });
 }

Angel Petrov
Telerik team
 answered on 29 Aug 2016
1 answer
192 views

Hi, is it posible to have 

  @(Html.Kendo().DatePickerFor(model => model.BeginDate)

with a masked input?

I want to have the option to write the date but with a mask like 00/00/0000

Thanks

Eyup
Telerik team
 answered on 26 Aug 2016
4 answers
621 views
I am using the latest kendo Grid script client with batch edit. Here is my code:
$("#Contract").kendoGrid({ 
  columns: [
     {
field: "SomeField",
 }],
editable: true,
scrollable: true,
navigatable: true,
selectable: "cell"

How do I make the cell selected when users click on a cell?
I saw a demo at http://demos.telerik.com/aspnet-mvc/razor/grid/editingbatch and wanted to do the same but I could not figure which setting is needed. For editable setting, I tried 0,1,and 2 but it does not seem to work like telerik grid.
Terry
Top achievements
Rank 1
 answered on 26 Aug 2016
3 answers
210 views

Is there any information on using the Scheduler with the Microsoft Exchange Web Services API?

It seems like it would be a good fit to use calendar information from Exchange Services.

 

Vladimir Iliev
Telerik team
 answered on 26 Aug 2016
3 answers
954 views
Hi all,

I was wondering if it was possible to disable/hide the paging feature dynamically when only 1 page is shown, i.e. PageSize is set to 100, but the data only consists of 70 rows.

Thanks!

Lennart
Timothy
Top achievements
Rank 1
 answered on 26 Aug 2016
1 answer
553 views

Hi, I would like to scrolling a Kendo UI MVC Grid vertically but not horizontally.

.Scrollable(scroll => scroll.Height(80).Enabled(true))  make it scrolls  vertically and horizontally.

Konstantin Dikov
Telerik team
 answered on 26 Aug 2016
1 answer
479 views

Hi,

I'm using kendo ui scheduller custom editor template.

How can I change the popup title from defaut (event) to (My Task Name) ?

See attached file

Best regards

Nencho
Telerik team
 answered on 26 Aug 2016
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
Jake
Top achievements
Rank 1
RBarnes
Top achievements
Rank 1
Iron
Iron
Rami
Top achievements
Rank 1
Iron
Veteran
Nathan
Top achievements
Rank 1
Kumeri
Top achievements
Rank 1
Iron
Veteran
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jake
Top achievements
Rank 1
RBarnes
Top achievements
Rank 1
Iron
Iron
Rami
Top achievements
Rank 1
Iron
Veteran
Nathan
Top achievements
Rank 1
Kumeri
Top achievements
Rank 1
Iron
Veteran
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?