HI I am stuck with getting the data that I need to display in kendo UI GRID. Initially, I can see the button and the text box and the grid, but when I enter the value in the text box and then press the button, I need to show that the entered values ββin the UI GRID kendo ...
When I launched this application in google chrome, it gave an empty grid after entering the value, and then click the submit button, but when I launched this file in IE8, it gave an error like this at the very initial stage ....
Unhandled exception at line 238, column 37 in Function code 0x800a138f - Microsoft JScript runtime error: 'data.EmployeeDetails.EmployeeId' is null or not an object
and this is my model
public class TextBoxGrid { public string EnteredValue { get; set; } public List<EmployeeDetails> employees; } public class ParentViewModel { public EmployeeDetails EmployeeDetails { get; set; } public TextBoxGrid TextBoxGrid { get; set; } } public class EmployeeDetails { public string EmployeeId { get; set; } public string ManagerId { get; set; } }
this is my controller
public class EnterValuesGridController : Controller { private static List<EmployeeDetails> empdtls; public ActionResult Index( ParentViewModel model) { var viewmodel = new ParentViewModel { TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() } }; return View(viewmodel); } [HttpPost] public ActionResult PostValues(TextBoxGrid model) { TempData["enteringValue"] = model.EnteredValue; var viewmodel = new ParentViewModel { TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() } }; //ParentViewModel p = new ParentViewModel(); //TextBoxGrid t = new TextBoxGrid(); //t.EnteredValue = "a"; //TempData["a1"] = t.EnteredValue; //t.employees = GetEmployee().ToList(); //p.TextBoxGrid = t; //return View("Index", p); return View("Index", viewmodel); } public IEnumerable<EmployeeDetails> GetEmployee() { string enteredValueId =(string) TempData["enteringValue"]; string managerId = "M" +enteredValueId; empdtls = new List<EmployeeDetails>(); EmployeeDetails em1 = new EmployeeDetails(); em1.EmployeeId = enteredValueId; em1.ManagerId = managerId; empdtls.Add(em1); return empdtls.AsEnumerable(); } public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request) { return Json(GetOrders().ToDataSourceResult(request)); } private IEnumerable<EmployeeDetails> GetOrders() { return GetEmployee().AsEnumerable(); } }
and this is my opinion
@model KendoPratapSampleMVCApp.Models.ParentViewModel @{ ViewBag.Title = "Index"; } @using (Html.BeginForm("PostValues", "EnterValuesGrid", FormMethod.Post)) { @Html.TextBoxFor(m=>m.TextBoxGrid.EnteredValue) <input type="submit" name="Submitbutton1" value="Submit1" /> @(Html.Kendo().Grid<KendoPratapSampleMVCApp.Models.ParentViewModel>() .Name("grid") .Columns(columns => { columns.Bound(s=>s.EmployeeDetails.EmployeeId).Filterable(false).Width(100); columns.Bound(s => s.EmployeeDetails.ManagerId).Filterable(false).Width(100); }) .Filterable() .HtmlAttributes(new { style = "height:430px;" }) .DataSource(dataSource => dataSource .Ajax() .PageSize(20) .Read(read => read.Action("Orders_Read", "EnterValuesGrid")) ) ) }
I am not sure where I am going wrong. Could you suggest any ideas on this. Thank you very much .... I need to make any changes to the UI GRID. I tried changing the post values ββmethod ... but it didnot work for me ...
UPDATE: changed tempData to view bag ...
[HttpPost] public ActionResult PostValues(ParentViewModel model) { ViewBag.item = model.TextBoxGrid.EnteredValue; var viewmodel = new ParentViewModel { TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() } }; //ParentViewModel p = new ParentViewModel(); //TextBoxGrid t = new TextBoxGrid(); //t.EnteredValue = "a"; //TempData["a1"] = t.EnteredValue; //t.employees = GetEmployee().ToList(); //p.TextBoxGrid = t; //return View("Index", p); return View("Index", viewmodel); } public IEnumerable<EmployeeDetails> GetEmployee() { string enteredValueId = (string)ViewBag.item; string managerId = "M" +enteredValueId; empdtls = new List<EmployeeDetails>(); EmployeeDetails em1 = new EmployeeDetails(); em1.EmployeeId = enteredValueId; em1.ManagerId = managerId; empdtls.Add(em1); return empdtls; }