nkat
Member
- Joined
 - Jun 29, 2022
 
- Messages
 - 21
 
- Programming Experience
 - 1-3
 
Hello!
Please, consider a simple .NET CORE app.
Controller
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
View
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
The app runs and if a user clicks “Save” button then
So, the question is. Would someone suggest a way to fill into the Grid data that has just been calculated in the POST event? “Orders_Read” event should only be used to browse between pages
	
		
			
		
		
	
				
			Please, consider a simple .NET CORE app.
Controller
			
				Controller:
			
		
		
		using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TelerikAspNetCoreApp1.Models;
namespace TelerikAspNetCoreApp1.Controllers
{
    public class HomeController : Controller
    {
        public IEnumerable<OrderViewModel> Records { get; set; }
        private bool dataready;
        public IActionResult Index()
        {
            dataready = false;
            return View();
        }
        [HttpPost]
        public IActionResult Index(string ServerIP)
        {
            Records = Enumerable.Range(0, 50).Select(i => new OrderViewModel
            {
                OrderID = i,
                Freight = i * 10,
                OrderDate = new DateTime(2016, 9, 15).AddDays(i % 7),
                ShipName = "ShipName " + i,
                ShipCity = "ShipCity " + i
            });
            dataready = true;
            return View();
        }
        public ActionResult Orders_Read([DataSourceRequest] DataSourceRequest request)
        {
            if (dataready)
            {
                var dsResult = Records.ToDataSourceResult(request);
                return Json(dsResult);
            }
            return (null);
        }
    }
}
	View
			
				View:
			
		
		
		<form id="Index" method="POST" asp-action="Index">
    <div class="k-w-500">
        <kendo-textbox value="172.16.23.197" name="ServerIP" style="width: 100%" placeholder="Server IP">
        <textbox-label content="Enter IP of the server"/>
        </kendo-textbox>
    </div>
    <div class="form-group form-inline row pull-right">
        <div class="col-sm-10 ">
            <button value="Save" style="margin:0 5px;" class="btn btn-navy">Save</button>
        </div>
    </div>
<input type="hidden" id="selectedCheckboxes" name="selectedCheckboxes">
</form>
@(Html.Kendo().Grid <TelerikAspNetCoreApp1.Models.OrderViewModel>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.OrderID).Filterable(false);
        columns.Bound(p => p.Freight);
        columns.Bound(p => p.OrderDate).Format("{0:MM/dd/yyyy}");
        columns.Bound(p => p.ShipName);
        columns.Bound(p => p.ShipCity);
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .HtmlAttributes(new { style = "height:550px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Read(read => read.Action("Orders_Read", "Home"))
        )
)
	The app runs and if a user clicks “Save” button then
public IActionResult Index(string ServerIP) fires, IEnumerable<OrderViewModel> Records  gets set and a flag dataready is up. But then the public ActionResult Orders_Read([DataSourceRequest] DataSourceRequest request)
 event fires (in a separate thread creating therefore a new Controller instance and as such -> “dataready” variable equals false and Records are no longer available). And this is the problem I'm trying to overcome.So, the question is. Would someone suggest a way to fill into the Grid data that has just been calculated in the POST event? “Orders_Read” event should only be used to browse between pages