Telerik Forums
UI for ASP.NET Core Forum
3 answers
612 views

I want to export the current sheet to xlsx and send it to the server. I use excel proxy to send the file to server. but when the server side process done. the ui will auto refresh. I want to receive the return value and not refresh the UI, how can I do this, please help.

 

server side code:

[HttpPost]
        public ActionResult Post()
        {
            try
            {
                var data = Request.Form;
                var file = data["base64"][0];
                var fileName = data["fileName"][0];
                var contentType = data["contentType"][0];
                byte[] buffer = Convert.FromBase64String(file);
                string filePath = FileHelper.MapPath("/wwwroot/UserUpload/" + fileName);
                FileStream fs = new FileStream(filePath, FileMode.CreateNew);
                fs.Write(buffer, 0, buffer.Length);
                fs.Close();
                return new JsonResult("OK");
            }
            catch (Exception e)
            {
                return new JsonResult("Fail");
            }
        }

Veselin Tsvetanov
Telerik team
 answered on 07 Jan 2020
1 answer
126 views

If one has a grid on a section of a page and follows the approach with inline editing, as in this example, will just the grid update and NOT the entire view?
https://demos.telerik.com/aspnet-core/grid/editing-inline

 

Alex Hajigeorgieva
Telerik team
 answered on 07 Jan 2020
4 answers
4.2K+ views

I have a grid that has an edit and a delete button.  I want to hide those buttons conditionally based on a specific value within the row.  How can I accomplish this?  For reference here is the current Grid create.

 

01.@(Html.Kendo()
02.      .Grid<CdEyeColor>()
03.      .Name("Codes")
04.      .DataSource(ds =>
05.      {
06.        ds.Ajax()
07.        .ServerOperation(true)
08.        .Model(m =>
09.        {
10.          m.Id(code => code.EyeColorId);
11.        })
12.        .Create(create => create.Action("CreateCode", "CdEyeColor"))
13.        .Read(read => read.Action("ReadCode", "CdEyeColor"))
14.        .Update(update => update.Action("EditCode", "CdEyeColor"))
15.        .Destroy(destroy => destroy.Action("DeleteCode", "CdEyeColor"));
16.      })
17.      .Columns(columns =>
18.      {
19.        columns.Bound(c => c.EyeColorTitle).Width(100);
20.        columns.Bound(c => c.EyeColorDescription).Width(200);
21.        columns.Bound(c => c.BeginDate).Width(100);
22.        columns.Bound(c => c.EndDate).Width(100);
23.        columns.Bound(c => c.changedByName).Width(150);
24.        columns.Bound(c => c.ChangedTimestamp).Width(200);
25.        columns.Bound(c => c.createdByName).Width(150);
26.        columns.Bound(c => c.CreatedTimestamp).Width(100);
27.        columns.Command(command =>
28.        {
29.          command.Edit().UpdateText("Update");
30.          command.Destroy();
31.        });
32.      })
33.      .ToolBar(toolbar => toolbar.Create())
34.      .HtmlAttributes(new { style = "height: 380px;" })
35.      .Scrollable()
36.      .Groupable()
37.      .Events(x => { x.Edit("onEdit"); x.Save("onGridSave"); })
38.      .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("EditorTemplateEyeColor").Window(window => { window.Title("Eye Color"); }))
39.      .Sortable()
40.      .Pageable(pageable => pageable
41.      .Refresh(true)
42.      .PageSizes(true)
43.      .ButtonCount(5))
44.)
Joel
Top achievements
Rank 3
Bronze
Iron
Iron
 answered on 06 Jan 2020
3 answers
344 views

I have a razorpage with a grid and these methods on the DataSource.

 

                        .Update(u => u.Url("/Audit?handler=Update").Data("forgeryToken"))
                        .Create(c => c.Url("/Audit?handler=Create").Data("forgeryToken"))
                        .Destroy(d => d.Url("/Audit?handler=Destroy").Data("forgeryToken"))

 

For some reason when I edit a row, then hit update, I get a 400 error as the request is being made for Audit?handler=Create instead of the Update handler?

What can I check?

My Update handler
        public JsonResult OnPostUpdate([DataSourceRequest] DataSourceRequest request, ViewLineItemModel localOrder)
        {

            // get updated order from parameter
            // save updates to db

           //....
            // test
            JsonResult r = new JsonResult(localOrder);
            return r;
        }

BitShift
Top achievements
Rank 1
Veteran
 answered on 06 Jan 2020
1 answer
975 views

hello, I'm working through a trial of UI for .NET Core and not having much luck with a very simple task. I'm following the example in the demo for cascading dropdowns and I can't even get the first dropdownlist to load. It just shows a list of items marked Undefined.

 

Here's the code from the View (Create.cshtml):

 

 <div class="form-group">
                <label asp-for="CategoryID" class="control-label"></label>
                @(Html.Kendo().DropDownList()
             .Name("categories")
             .HtmlAttributes(new { style = "width:100%" })
             .OptionLabel("Select category...")
             .DataTextField("CategoryName")
             .DataValueField("CategoryID")
             .DataSource(source =>
                     {
                  source.Read(read =>
                         {
                      read.Action("LoadCategories", "Groups");
                  });
             })
                )
                <span asp-validation-for="CategoryID" class="text-danger"></span>
            </div>


            <div class="form-group">
                <label asp-for="SubcategoryID" class="control-label"></label>
                
                @(Html.Kendo().DropDownList()
              .Name("subcategories")
              .HtmlAttributes(new { style = "width:100%" })
              .OptionLabel("Select subcategories...")
              .DataTextField("SubcategoryName")
              .DataValueField("SubcategoryID")
              .DataSource(source =>
              {
                  source.Read(read =>
                  {
                      read.Action("LoadSubcategories", "Groups")
                          .Data("filterSubcategories");
                  })
                  .ServerFiltering(true);
              })
              .Enable(false)
              .AutoBind(false)
              .CascadeFrom("categories")
                )

                <span asp-validation-for="SubcategoryID" class="text-danger"></span>
            </div>

            <script>
                function filterSubcategories() {
                    return {
                        categories: $("#categories").val()
                    };
                }
            </script>

 

 

Here's the code from GroupsController.cs:

 

public JsonResult LoadCategories()
        {
            List<Category> categories = new List<Category>();

            var catQuery = from d in _context.Category
                             where d.IsActive
                             orderby d.CategoryName // Sort by name.
                             select d;


            categories = catQuery.ToList();

            return new JsonResult(categories);
        }

        public JsonResult LoadSubcategories(int? categories)
        {
            List<Subcategory> subcategories = new List<Subcategory>();

            var catQuery = from d in _context.SubCategory
                           where d.CategoryID == categories.GetValueOrDefault()
                           orderby d.SubCategoryName // Sort by name.
                           select d;


            subcategories = catQuery.ToList();

            return new JsonResult(subcategories);
        }

 

I get the same result when using code in GroupsController LoadCategories more similar to your demo source code:

return Json(_context.Category
                     .Select(c => new { CategoryID = c.CategoryID, CategoryName = c.CategoryName }).ToList());

 

 

Plamen
Telerik team
 answered on 02 Jan 2020
8 answers
221 views

Clicking on item in DropDownList in a Grid Popup Editor causes a javascript "undefined" error. Attached are screen shots from the Chrome debugger. Relevant code is below:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using TelerikTest.Models;
using System.Net.Http;
using Newtonsoft.Json;
using System.Text;
using System.IO;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;

namespace TelerikTest.Controllers {
   public class PeopleController : Controller {

      public PeopleController() {
         }

      private List<Person> InitPersons() {
         var persons = new List<Person>();
         persons.Add(new Person() { Id = 1, FirstName = "Joe", LastName = "Smith", JobTitle = "President", Street = "409 State St.", City = "Chicago", State = "IL", Zip = "60606" });
         persons.Add(new Person() { Id = 2, FirstName = "Bob", LastName = "Brown", JobTitle = "Vice President", Street = "1200 Fifth Ave.", City = "New York", State = "NY", Zip = "10005" });
         return persons;
         }

      public IActionResult Index() {
         var persons = InitPersons();
         return View(persons);
         }

      public IActionResult EditForms(int id) {
         var persons = InitPersons();
         var person = persons.Single(x => x.Id == id);
         ViewData["name"] = person.LastName;

         var cfi = new List<CategoryFormItem>();
         cfi.Add(new CategoryFormItem() { id = 1, category = "Medical", form = "Medical Conditions" });
         cfi.Add(new CategoryFormItem() { id = 2, category = "Medical", form = "Physical" });
         cfi.Add(new CategoryFormItem() { id = 3, category = "Permission", form = "Participation" });
         cfi.Add(new CategoryFormItem() { id = 4, category = "Permission", form = "Travel" });
         cfi.Add(new CategoryFormItem() { id = 5, category = "Incident", form = "Behavior" });
         cfi.Add(new CategoryFormItem() { id = 6, category = "Incident", form = "Injury" });

         var cf = new List<CategoryForm>();
         foreach (var f in cfi) {
            var c = new CategoryForm();
            c.id = f.id;
            c.cf = $"{f.category}: {f.form}";
            cf.Add(c);
            }

         ViewData["categoryforms"] = cf;

         var pforms = new List<PersonFormViewModel>();
         var vmForm = new PersonFormViewModel() { id = 1, category = "Medical", formId = 1, name = "Physical", personId = id, received = DateTime.Today, remarks = "Required physical" };
         pforms.Add(vmForm);

         return View(pforms);
         }

      public IActionResult CreateForm([DataSourceRequest]DataSourceRequest request, [FromForm] PersonFormViewModel vm) {
         return Json(new[] { vm }.ToDataSourceResult(request, ModelState));
         }

      public IActionResult UpdateForm([DataSourceRequest]DataSourceRequest request, PersonFormViewModel vm) {
         return Json(new[] { vm }.ToDataSourceResult(request, ModelState));
         }

      public IActionResult DeleteForm([DataSourceRequest]DataSourceRequest request, PersonFormViewModel vm) {
         return Json(new[] { vm }.ToDataSourceResult(request, ModelState));
         }
      }
   }

 

 

@model IEnumerable<TelerikTest.Models.PersonFormViewModel>
@using Kendo.Mvc.UI

@section Scripts {
<script type="text/javascript">
    function onDataBound() {
        var btn = $("#addPeopleForm").data("kendoButton");
        if (btn == undefined) {
            $("#addPeopleForm").kendoButton({
                icon: "plus",
                click: function (e) {
                    e.preventDefault();
                    var grid = $('#gridPersonForms').data('kendoGrid');
                    grid.addRow();
                }
            });
        }
    };
</script>
}

<div class="text-center">
     <h1 class="display-4">@ViewData["name"]</h1>
</div>
<div>
    @(Html.Kendo().Grid<PersonFormViewModel>(Model)
       .Name("gridPersonForms")
       .Columns(columns => {
           columns.Bound(c => c.id).Hidden();
           columns.Bound(c => c.personId).Hidden();
           columns.Bound(c => c.formId).Hidden();
           columns.Bound(c => c.category).Hidden().ClientGroupHeaderTemplate("#= value #");
           columns.Bound(c => c.catfrm).Hidden();
           columns.Bound(c => c.name).Width(100).Title("Form");
           columns.Bound(c => c.received).Width(60).Title("Date Received");
           columns.Bound(c => c.remarks).Title("Remarks");
           columns.Command(c => { c.Edit(); c.Destroy(); }).Width(250).ClientHeaderTemplate("<button id='addPeopleForm'>Add New Form Receipt</button>");
       })
       .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("AddPeopleForm"))
       .Events(e => e.DataBound("onDataBound"))
       .Selectable(s => s.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
       .DataSource(dataSource => dataSource
           .Ajax()
           .Model(m => m.Id(p => p.id))
           .Create("CreateForm", "People")
           .Update("UpdateForm", "People")
           .Destroy("DeleteForm", "People")
           .Group(g => g.Add(x => x.category))
           .ServerOperation(false)
           )
    )
</div>

using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace TelerikTest.Models {
   public class PersonFormViewModel {
      public int id { get; set; }
      public int personId { get; set; }
      public int formId { get; set; }

      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString ="{0:MM/dd/yyyy}")]
      [DataType(DataType.Date)]
      [DisplayName("Date Received")]
      public DateTime received { get; set; }

      [DisplayName("Remarks")]
      public string remarks { get; set; }

      public string category { get; set; }
      public string name { get; set; }

      [UIHint("CategoryFormEditor")]
      [DisplayName("Category: Form")]
      public CategoryForm catfrm { get; set; }

      public PersonFormViewModel() {
         }
      }
   }

@model TelerikTest.Models.PersonFormViewModel

<div class="k-edit-form-container">
    @Html.HiddenFor(m => m.id)
    @Html.HiddenFor(m => m.personId)
    @Html.HiddenFor(m => m.formId)

    <div class="k-edit-label">
        @Html.LabelFor(model => model.catfrm)
    </div>
    <div class="k-edit-field">
        @Html.EditorFor(model => model.catfrm)
        @Html.ValidationMessageFor(model => model.catfrm)
    </div>

    <div class="k-edit-label">
        @Html.LabelFor(model => model.received)
    </div>
    <div class="k-edit-field">
        @Html.EditorFor(model => model.received)
        @Html.ValidationMessageFor(model => model.received)
    </div>
    <div class="k-edit-label">
        @Html.LabelFor(model => model.remarks)
    </div>
    <div class="k-edit-field">
        @Html.EditorFor(model => model.remarks)
        @Html.ValidationMessageFor(model => model.remarks)
    </div>
</div>

 

@using Kendo.Mvc.UI

@(Html.Kendo().DropDownList()
   .Name("catfrm")
   .DataValueField("id")
   .DataTextField("cf")
   .BindTo((System.Collections.IEnumerable) ViewData["categoryforms"])
   )

using System;
namespace TelerikTest.Models {
   public class CategoryForm {
      public int id { get; set; }
      public string cf { get; set; }

      public CategoryForm() {
         }
      }

   public class CategoryFormItem {
      public int id { get; set; }
      public string category { get; set; }
      public string form { get; set; }

      public CategoryFormItem() {
         }
      }
   }

Tsvetomir
Telerik team
 answered on 30 Dec 2019
3 answers
1.8K+ views

Hi,

I have some values that are DateTimeOffsets. I'm having trouble formatting them in a grid though.

This code:

columns.Bound(c => c.StartTimestamp).Width(750).Format("{0:dd/MM/yyyy HH:mm:ss}");

produces:

2019-06-06T17:47:52.0256922+01:00

when what I want to see is:

06/06/2019 17:47:52

Is the Grid unable to format DateTimeOffsets, or am I missing something?

Thanks,

Gary

Alex Hajigeorgieva
Telerik team
 answered on 30 Dec 2019
3 answers
907 views
I am having an issue with my menu control.  I am trying to get the last item to float right.  I found a post that seem to be related to what I am trying to do but it is from 2013 and for JQuery. Also the solution does not seem to work for me.
https://www.telerik.com/forums/moving-the-right-most-menu-all-the-way-to-the-right-or

Using css and seting #menuName > .k-last honors all aspects (border, font, color..) but the float:right.  Is it something simple I am missing here?
Rick
Top achievements
Rank 1
 answered on 27 Dec 2019
4 answers
182 views

Hi,

I have 4 columns (Round1, Round2, Round3, Total) of which Total is a non editable int column.Whenever user updates Round1, 2 and 3 by clicking Update.. The total is saved in the database using Employee_Update action and my hope is that Total column will automatically refresh.  But thats not happening. Only Round1, 2 and 3 refresh.

 

Here is my grid

@(Html.Kendo().Grid<EmployeeManagement.Models.Employee>()
                    .Name("EmployeeGrid")
                    .Columns(columns =>
                    {

                        columns.Bound(p => p.EmployeeID);
                        columns.Bound(p => p.Round1);
                        columns.Bound(p => p.Round2);
                        columns.Bound(p => p.Round3);
                        columns.Bound(p => p.Total).Width(100);
                        columns.Command(command => { command.Edit(); }).Width(250);
                    })
                    .Editable(editable => editable.Mode(GridEditMode.InLine))
                    .Pageable(a => a.PageSizes(new int[] { 50, 100 }))
                    .Sortable()
                    .Scrollable()
                    .HtmlAttributes(new { style = "height:700px;" })
                    .Events(events => { events.Save("updateTotal"); }
                    )
                .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(100)
                .Model(model =>
                {
                    model.Id(p => p.EmployeeID);
                    model.Field(p => p.Total).Editable(false);
                })

                .Update(update => update.Action("Employee_Update", "Admin"))

        )
    )

 

<script>

function updateTotal(e) {

        var totalCount = 0;
        if (e.model.Round1 !== null)
            totalCount += 1;
        if (e.model.Round2 !== null)
            totalCount += 1;
        if (e.model.Round3 !== null)
            totalCount += 1;
        
        // totalCount has correct total

e.model.set('Total', totalCount); // Doesnt refresh

e.container.parents('tr').find('td:eq(4)').html(totalCount); // Doesnt refresh

        e.container[0].children[4].innerText = totalCount; // Doesnt refresh

    }

</script>

 

There are no developer tools console errors.

StuartLittle
Top achievements
Rank 1
 answered on 27 Dec 2019
3 answers
678 views

can someone supply a complete set of instructions on how to apply the all.css and variables.scss files downloaded from the SASS Themebuilder to my .Net Core project

There seems to be no documentation regarding this for telerik ui for asp.net core

thanks

 

Jim

Preslav
Telerik team
 answered on 26 Dec 2019
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?