Hi,
I am new to Telerik at. I have a scenario where I click on the grid record I am taken to a form with the values populated. With the help of some online resources I was able to populate when the form and grid was kept in the same view. However, when I have a separate view I don't get my values populated.Where am I going wrong? Any help is greatly appreciated. Thanks in advance
My grid looks like - Index.cshtml
@(Html.Kendo().Grid<TabGrid.Models.ORM_MT_STATUS>() .Name("grid") .Columns(columns => { columns.Bound(c => c.STATUS_ID); columns.Bound(c => c.STATUS_DESCRIPTION); columns.Bound(c => c.CreatedBy); columns.Bound(c => c.CreatedDate); columns.Bound(c => c.CreatedIP); columns.Bound(c => c.UpdatedBy); columns.Bound(c => c.UpdatedDate); columns.Bound(c => c.UpdatedIP); ; }) .ToolBar(toolbar => { toolbar.Excel(); }) .ColumnMenu() .Pageable() .Navigatable() .Selectable(selectable => { selectable.Mode(GridSelectionMode.Single); selectable.Type(GridSelectionType.Row); }) .Sortable(sortable => { sortable.SortMode(GridSortMode.SingleColumn); }) .Filterable() .Scrollable() .Events(events => { events.Change("onChange"); }) .DataSource(dataSource => dataSource .Ajax() .Read(read => read.Action("ORM_MT_STATUS_Read", "Status")) ))<script> function fillForm(dataItem) { var columns = $("#grid").data("kendoGrid").options.columns; var id = dataItem.STATUS_ID; var form = $("form"); for (var i = 0; i < columns.length; i++) { var field = columns[i].field; form.find("#" + field).val(dataItem[field]); } // window.location.href = "@Url.Action( "form", "Status")" + "?STATUS_ID" + id; } function onChange(e) { //var grid = $("#grid").data("kendoGrid"); var dataItem = this.dataItem(this.select()); fillForm(dataItem); }</script>
My form looks like - form.cshtml
@{ ViewBag.Title = "form";}<h2>form</h2><div class="demo-section k-content capitalize"> <div id="validation-success"></div> @(Html.Kendo().Form<TabGrid.Models.ORM_MT_STATUS> () .Name("form") .HtmlAttributes(new { action = "form", method = "POST" }) .Validatable(v => { v.ValidateOnBlur(true); v.ValidationSummary(vs => vs.Enable(true)); }) .Items(items => { items.AddGroup() .Label("Status Management Form") .Items(i => { i.Add() .Field(f => f.STATUS_ID).InputHtmlAttributes(new{ @readonly ="readonly"}) .Label(l => l.Text("ID:")); i.Add() .Field(f => f.STATUS_DESCRIPTION) //.InputHtmlAttributes(class="capitaize") .InputHtmlAttributes(new { onkeyup = "this.value = this.value.initcaps();" }) .Label(l => l.Text("Status:")); }); }) .Events(ev => ev.ValidateField("onFormValidateField").Submit("onFormSubmit").Clear("onFormClear")) )</div>@*<div>@Html.Action("Add")</div>*@<script> function disablefield() { document.getElementById("id").disabled = true; } function onFormValidateField(e) { $("#validation-success").html(""); } function onFormSubmit(e) { e.preventDefault(); $("#validation-success").html("<div class='k-messagebox k-messagebox-success'>Form data is valid!</div>"); } function onFormClear(e) { $("#validation-success").html(""); }</script>