Telerik Forums
UI for ASP.NET Core Forum
3 answers
1.2K+ views

Hello,

is there any possibility to add an additional value to the ToDataSourceResult in the Kendo read Action to pass that value with
the Ajax request to the Client?

return Json(result.ToDataSourceResult(request));

 

Background: we have a paged grid and in my action I pass the ID of a row which is added to the database with a Ajax form outside the grid
and calculate on the Server the page for that row so I want to pass that page as an additional value to the client:
https://www.telerik.com/forums/find-row-and-select-it-in-grouped-sorted-and-paged-grid#nF26Ya0-hkqiWAdfUkaSuQ

robert

Georgi
Telerik team
 answered on 28 Feb 2018
2 answers
251 views

What am I doing wrong.  I have a grid that refuses to post back to the proper action in the controller.  It continually goes back to the (get) Index action even though in the grid I am calling an action called Cleanup_Update.  When initially calling the page Cleanup_Read works fine.  Only when editing the inside of the grid and hitting save changes is it not going where it should go. 

Thanks in advance

 

View

@{
    ViewData["Title"] = "Index";
}
@Html.AntiForgeryToken()
 
<h2>Index</h2>
 
@(Html.Kendo().Grid<FacilityDataManagerMVC.Models.ViewModels.ErrorCleanup>
                ()
                .Name("grid")
                .Columns(columns =>
                {
                    columns.Bound(c => c.ID).Width(150);//.Hidden(true);
        columns.Bound(c => c.stationAssetID).Width(140).Filterable(ftb => ftb.Multi(true).CheckAll(true));
                    columns.Bound(c => c.stationID).Width(140).Filterable(ftb => ftb.Multi(true).CheckAll(true));
                    columns.Bound(c => c.errorType).Width(110).Filterable(ftb => ftb.Multi(true).CheckAll(true));
                    columns.Bound(c => c.readingDate).Width(110).Format("{0:MM/dd/yyyy}").Filterable(ftb => ftb.Multi(true).CheckAll(true));
        //columns.Bound(c => c.errorCorrected).Width(25);
        //change the column above to a checkbox
        columns.Bound(c => c.errorCorrected).ClientTemplate("<input type='checkbox' disabled='true' value='#= errorCorrected #' " + " # if (errorCorrected) { #" + "checked='checked'" + "# } #" + "/>");
                    columns.Bound(c => c.operatingHours).Width(25);
                    columns.Bound(c => c.totalDowntimeHours).Width(25);
                    columns.Bound(c => c.horsepowerHours).Width(25);
                    columns.Bound(c => c.fuelConsumed).Width(25);
                    columns.Bound(c => c.engineStartAttempts).Width(25);
                    columns.Bound(c => c.engineStartFailed).Width(25);
                    columns.Bound(c => c.engineStartSuccess).Width(25);
                    columns.Bound(c => c.startupDuration).Width(25);
                    columns.Bound(c => c.throughputMMCF).Width(25);
                    columns.Bound(c => c.averageUnitRPM).Width(25);
                    columns.Bound(c => c.oilUsageCompressor).Width(25);
                    columns.Bound(c => c.oilUsageEngine).Width(25);
                    columns.Bound(c => c.oilUsageManual).Width(25);
                })
                .ToolBar(toolbar =>
                {
                    toolbar.Save();
                })
                .Editable(editable => editable.Mode(GridEditMode.InCell))
                .Sortable()
                .Filterable()
                .Pageable()
                .Navigatable()
                .DataSource(dataSource => dataSource
                .Ajax()
                .Batch(true)
                .PageSize(20)
                .ServerOperation(false)
                .Events(events => events.Error("error_handler"))
                //set the fields to non-editable here
                .Model(model =>
                {
                    model.Field(p => p.ID).Editable(false);
                    model.Field(p => p.stationID).Editable(false);
                    model.Field(p => p.readingDate).Editable(false);
                    model.Field(p => p.errorType).Editable(false);
                    model.Field(p => p.stationAssetID).Editable(false);
                    model.Field(p => p.errorCorrected).Editable(false);
                })
                .Read(read => read.Action("Cleanup_Read", "Cleanup").Data("sendAntiForgery"))
                .Update(update => update.Action("Cleanup_Update", "Cleanup").Data("sendAntiForgery"))
                )
)
<script type="text/javascript">
    function error_handler(e) {
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });
            alert(message);
        }
    }
</script>
<script type="text/javascript">
    function sendAntiForgery() {
        return { "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val() }
    }
</script>
<style>
    .k-readonly {
        color: gray;
    }
</style>

Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using FacilityDataManagerMVC.Data;
using FacilityDataManagerMVC.Models.ViewModels;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
 
namespace FacilityDataManagerMVC.Controllers
{
 
    public class CleanupController : Controller
    {
        private readonly FacilityDataManagerMVCContext _context;
 
        public CleanupController(FacilityDataManagerMVCContext context)
        {
            _context = context;
        }
        // GET: Cleanup
        public ActionResult Index()
        {
            return View();
        }
 
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult IndexPost([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ErrorCleanup> errors)
        {
 
            if (errors != null && ModelState.IsValid)
            {
                foreach (var product in errors)
                {
                    //productService.Update(product);
                    string x = "mystring";
                }
            }
 
            return Json(errors.ToDataSourceResult(request, ModelState));
        }
 
        [HttpPost]
        [ValidateAntiForgeryToken]
        public IActionResult Cleanup_Update([DataSourceRequest] DataSourceRequest request, [Bind]IEnumerable<ErrorCleanup> errors)
        {
            if (errors != null && ModelState.IsValid)
            {
                foreach (var product in errors)
                {
                    //productService.Update(product);
                    string x = "mystring";
                }
            }
 
            return Json(errors.ToDataSourceResult(request, ModelState));
        }
       
        public IActionResult Cleanup_Read([DataSourceRequest] DataSourceRequest request)
        {
            return Json(getScadaErrors().ToDataSourceResult(request));
        }
        private IEnumerable<ErrorCleanup> getScadaErrors()
        {
            using (_context)
            {
                return _context.ScadaErrors.Select(scadaError => new ErrorCleanup
                {
                    ID = scadaError.Id,
                    stationAssetID = scadaError.StationAssetId,
                    stationID = scadaError.StationId,
                    errorType = scadaError.ErrorType,
                    readingDate = scadaError.ReadingDate,
                    operatingHours = scadaError.OperatingHrs,
                    totalDowntimeHours = scadaError.TtlDowntimeHrs,
                    horsepowerHours = scadaError.HrsepwrHrs,
                    fuelConsumed = scadaError.FuelConsumed,
                    engineStartAttempts = scadaError.EngineStartsAttempts,
                    engineStartFailed = scadaError.EngineStartsFailed,
                    engineStartSuccess = scadaError.EngineStartsSuccess,
                    startupDuration = scadaError.StartupDuration,
                    throughputMMCF = scadaError.ThruputMmcf,
                    averageUnitRPM = scadaError.AvgUnitRpm,
                    oilUsageCompressor = scadaError.OilToCompCyl,
                    oilUsageManual = scadaError.OilNewCcHand,
                    errorCorrected = scadaError.ErrorCorrected
                    //blowdownCount = (int)scadaError.BlowdownCnt
                }
                ).ToList();
            }
        }
    }
}

 

 

 

 

Michael
Top achievements
Rank 1
 answered on 27 Feb 2018
1 answer
114 views

On the documentation for the Grid located here:

 

https://docs.telerik.com/aspnet-core/helpers/html-helpers/grid

I see a reference to the ProductService but don't see that as part of the sample on that page.  Where can this code be found. 

Preslav
Telerik team
 answered on 21 Feb 2018
3 answers
357 views

Hi,

I'm trying to add server filtering to the shared data source example on the demo site (Shared DataSource)

How can I add the .ServerFiltering(true) option to either the AutoComplete control or the DataSource ? 

Thanks,

Richard 

 

@(Html.Kendo().DataSource<Kendo.Mvc.Examples.Models.ProductViewModel>()
    .Name("dataSource1")
    .Ajax(dataSource => dataSource
       .Read(read => read.Action("Products_Read", "DataSource"))
       .ServerOperation(true)
     -->> .ServerFiltering(true) << --
    )
)
 
 
@(Html.Kendo().AutoComplete()
    .Name("autoComplete")
    .DataTextField("ProductName")
    .Filter(FilterType.Contains)
    .MinLength(2)
    .DataSource("dataSource1") -->> .ServerFiltering(true) <--
)
Richard
Top achievements
Rank 2
Iron
Iron
Veteran
 answered on 20 Feb 2018
1 answer
412 views

Hello,

I'm currently facing a problem with the ASP.NET Core Grid using the tag structure. My grid has the following structure:

<kendo-grid name="someGrid" deferred="true">
    <datasource page-size="20" type="DataSourceTagHelperType.Ajax" server-operation="false" server-grouping="false">
        <transport>
            <read url="some url" type="post"/>
        </transport>
        <sorts>
            <sort field="Id" direction="asc"/>
        </sorts>
    </datasource>
    <pageable button-count="5" refresh="true" page-sizes="new int[] { 5, 10, 20, 50 }"/>
    <filterable enabled="true"/>
    <scrollable enabled="true"/>
    <sortable enabled="true"/>
    <groupable enabled="false"/>
    <columns>
        <column field="Id" title="Id"/>
        <column field="Name" title="Name"/>
    </columns>
</kendo-grid>

An error occur in kendo.all.min.js (kendo.all.js) where it is executing the function _isServerGrouped(). In that particular function it tries to execute the function this.group() only that function does not exist. Did I forget to include something or is this a bug in the Grid using the taghelper? Even when server-grouping is set to false it is still trying to execute that particular function this.group() before it is going to check if the server-grouped is used or not (see image).

The back-end receives the appropriate call from the grid and is sending simple data as a JSON format back to the front-end (I've followed the example on the following page(s): https://docs.telerik.com/aspnet-core/helpers/tag-helpers/grid and https://demos.telerik.com/aspnet-core/grid/tag-helper).

Kendo-UI version: https://bower.telerik.com/bower-kendo-ui.git#~2018.1.131 (private repository)
asp.net core version: 2.0

Thank you in advance.

Angel Petrov
Telerik team
 answered on 16 Feb 2018
6 answers
822 views

Hi,

I'm using Telerik UI for in a .Net Core 2.0 application in order to display multiple rich text editors in the same page, to achieve this, I'm using multiple Kendo UI Editors.

When the page is loading, it takes over 20 seconds to load kendo.all.min.js.map and kendo.aspnetmvc.min.js.map.

The page holds 20 Kendo UI Editors, each one is .Deferred() and loaded after kendo ui scripts are loaded at the end of the page.

Furthermore, css and scripts are stored in local and not taken throught CDN Service (tried also loading from CDN Service but it has the same loading issue).

I have to run application inside IE11 and console doesn't show any script error.

Do you have any suggestion about this?

Thank you in advance!

Dimitar
Telerik team
 answered on 16 Feb 2018
2 answers
202 views

Hello,

How to use drag & drop to move a row over another in Kendo grid?

then I need the source row ID and the target row ID in the drop event where I will make an Ajax call to merge the rows into one at Service SQLServer table...

robert

Robert Madrian
Top achievements
Rank 1
Veteran
Iron
 answered on 14 Feb 2018
7 answers
641 views

Hi, I'm having a weird issue with dropdownlists and date pickers. Basically they work fine if I dont scroll may page at all but when I scroll it looks like the dropdown or datepickers child items are stuck at the original position relative to my page height. 

I attached a screenshot of what is happening.

Most of my controls are pretty basic. Is there something I'm missing in the controls thats messing with the placement of the child items?

Here is one of my drop down lists:

<div class="form-group">
    <label asp-for="timezone" class="user-label col-md-2"></label>
    <div class="col-md-4">
        @(Html.Kendo().DropDownList()
            .Name("timezone")
            .DataTextField("Text")
            .DataValueField("Value")
            .OptionLabel("Select Time Zone")
            .BindTo(new List<SelectListItem>() {
                new SelectListItem() { Text = "0 EST", Value = "0" },
                new SelectListItem() { Text = "-1 CEN", Value = "-1" },
                new SelectListItem() { Text = "-2 MTN", Value = "-2" },
                new SelectListItem() { Text = "-3 PAC", Value = "-3" },
                new SelectListItem() { Text = "-4 ALA", Value = "-4" },
                new SelectListItem() { Text = "-5 HAW", Value = "-5" },
                new SelectListItem() { Text = "+1 ATL", Value = "1" },
                new SelectListItem() { Text = "+1.5 NFI", Value = "1.5" }
            })
            .Value(Model.timezone.ToString())
        )
    </div>
</div>

 

Here is one of my date pickers:

<div class="form-group">
    <label asp-for="sign_on_expiry_date" class="user-label col-md-2"></label>
    <div class="col-md-4">
        @(Html.Kendo().DatePicker()
            .Name("sign_on_expiry_date")
            .Value(Model.sign_on_expiry_date)
        )
    </div>
</div>
neet-o
Top achievements
Rank 1
 answered on 14 Feb 2018
10 answers
132 views
ho

hi All,
I have a razor view "CDIS.cshtml" which is using a model object to render content. Now in this view, i have a submit button which calls an action method of the controller. In this action method, i need to use the same model object, which was used to render data in the previous view. My controller action method somehow gets the model object from the view, but it is empty. My target in the controller action is to use the same model object's values, which were used in the last view.
CDIS.cshtml

<p><br>@model MvcMovie.Controllers.Rootobject;
 
 
@{
    ViewData["Title"] = "CDIS subordinates";
}
<h2>@ViewData["Title"] for Group ID: <b>@Html.DisplayFor(model => model.data[0].groupId)</b></h2>
<h3>@ViewData["Message"]</h3>
 
 
<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.data[0].id)
            </th>
 
 
 
            <th>
                @Html.DisplayNameFor(model => model.data[0].fullName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.data[0].sourceSystem)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.data)
        {
 
            if (item.sourceSystem != "CRYSTAL_GLOBAL")
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.id)
                    </td>
 
                    <td>
                        @Html.DisplayFor(modelItem => item.fullName)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.sourceSystem)
                    </td>
                </tr>
            }
 
        }
 
        <tr>
 
            <td>
                <form asp-controller="CDISRecords" asp-action="CONIS" method="get">
                    <p>
                        <input type="hidden" name="GroupID" value="@Html.DisplayFor(model => model.data[0].groupId)">
 
                        <input type="hidden" name="dataModel" value=@Html.DisplayFor(model => model.data)>
                        <input type="hidden" name="dModel" asp-for="@Model.data" />
                        <div>
                            <input type="submit" value="GET Consent" class="btn btn-default" />
 
                            | For Date | :
                            <input type="date" name="consentDate">
                        </div>
                    </p>
                </form>
 
            </td>
        </tr>
    </tbody>
</table> <br></p><p></p>

CDISController.cs
    

 public async Task<IActionResult> CONIS(int? GroupID, MvcMovie.Controllers.Datum rootobject, MvcMovie.Controllers.Datum dModel)
        {
                Console.WriteLine($"City CONIS: " + dModel.city + "Group ID CONIS: " + rootobject.groupId + "Full Name CONIS : " + dModel.fullName);
             
 
            return View();
        }

 

 

In the above controller action, i have tried different ways to pass the model from the view, but each time, the values *-> City CONIS: " + dModel.city + "Group ID CONIS: " + rootobject.groupId + "Full Name CONIS : " + dModel.fullName *, are empty.

On the console, I see the following:

MvcMovie> Executing action method MvcMovie.Controllers.CDISRecordsController.CONIS (MvcMovie) with arguments (39256600, MvcMovie.Controllers.Datum, MvcMovie.Controllers.Datum) - ModelState is Valid
MvcMovie> City CONIS: Group ID CONIS: 39256600Full Name CONIS :

---

Perhaps my approach is incorrect, or I am passing the model reference incorrectly, because "City CONIS" is empty and Full Name CONIS is also empty. Somehow, Group ID CONIS is showing value. I have alos tried, for City and Name with "rootobject" like $"City CONIS: " + rootobject.city, but empty.
Any help shall highlly be appreciated. In nutshell, I need the values (appearing the table inside a view) to be passed to the controller to do further action. The values in the view are not fixed number of textfields rather values that i am showing in the table, hence i need the object to be passed further so that i can iterate on the object. 


Neli
Telerik team
 answered on 14 Feb 2018
2 answers
261 views

Is it possible to add the AutoComplete control to the ToolBar 

I was trying something like this but I don't think I'm on the right track.

Thanks,

Richard

@(Html.Kendo().ToolBar()
    .Name("ToolBar")
    .Items(items =>
    {
        items.Add().Type(CommandType.Button).Text("Button");
        items.Add().Type(CommandType.Button).Text("Toggle Button").Togglable(true);
 
        items.Add().Type(CommandType.Separator);
 
        items.Add().Template("<label for='dropdown'>Search:</label>");
        items.Add().Template(
            @(Html.Kendo().AutoComplete()
                .Name("GridSearch")
                .DataTextField("AppName")
                .Filter(FilterType.Contains)
                .MinLength(2)
                .DataSource("GridDataSource")
                ) ;
Richard
Top achievements
Rank 2
Iron
Iron
Veteran
 answered on 14 Feb 2018
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?