Hello Telerik and other developers,
I am facing an issue with submitting a grid within a form in dotnet core 6.
I followed the example from github but data does not pass from the grid form to the view.
The rest of the values from the form do pass, except the values from the grid.
I appreciate any help. Thank you.
<form asp-action="CreatePO" id="PorequestForm" name="PorequestForm"><div asp-validation-summary="ModelOnly" class="text-danger"></div><fieldset><legend>Materials</legend>
@*@Html.LabelFor(category => category.Justification)
@Html.EditorFor(category => category.Justification)*@
@(
Html.Kendo().Grid(Model.POMaterials)
.Name("PoMaterial")
.ToolBar(tools => tools.Create().Text("Add PO Materials"))
.Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
.Columns(columns =>
{
columns.Bound(p => p.ItemNumber).ClientTemplate("#= ItemNumber #" +
"<input type='hidden' name='POMaterial[#= index(data)#].ItemNumber' value='#= ItemNumber #' />"
);
columns.Bound(p => p.Description).ClientTemplate("#= Description #" +
"<input type='hidden' name='POMaterial[#= index(data)#].Description' value='#= Description #' />"
);
columns.Bound(p => p.Amount).ClientTemplate("#= Amount #" +
"<input type='hidden' name='POMaterial[#= index(data)#].Amount' value='#= Amount #'/>"
);
columns.Bound(p => p.UnitCost).ClientTemplate("#= UnitCost #" +
"<input type='hidden' name='POMaterial[#= index(data)#].UnitCost' value='#= UnitCost #' />"
);
columns.Bound(p => p.PomaterialId).Hidden().ClientTemplate("#= PomaterialId #" +
"<input type='hidden' name='POMaterial[#= index(data)#].PomaterialId' value='#= PomaterialId #' />"
);
columns.Command(command => command.Destroy()).Width(100);
})
.DataSource(dataSource => dataSource.Ajax()
.Model(model =>
{
model.Id(p => p.PomaterialId);
model.Field(p => p.PomaterialId).Editable(false);
})
.Batch(true)
//.Read(read => read.Action("ReadPoRequest", "Grid"))
//.Create(create => create.Action("AddPORequest", "Grid"))
.ServerOperation(false)
)
)
</fieldset>
</form>
<script>
function index(dataItem) {
var data = $("#PoMaterial").data("kendoGrid").dataSource.data();
return data.indexOf(dataItem);
}
</script>