New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Sending Additional Form Data in the Grid
Environment
Product | Telerik UI for ASP.NET MVC Grid |
Progress Telerik UI for ASP.NET MVC version | Created with the 2023.1.117 version |
Description
How can I pass a serialized form as an additional parameter to my controller when fetching data in the Telerik UI for ASP.NET MVC Grid?
Solution
To achieve the desired results:
- Provide a function handler by using the
Data()
configuration option for theRead
method of the Grid. - To get the form field as key-value pairs, utilize the
serializeArray()
within the handler. - Traverse through each of the fields, and alter them into your required format, which will then be displayed as a JSON object.
- Map the external fields to the JSON object.
- Pass the JSON object in the return statement of the handler.
Index.cshtml
// Form
<form id="userForm">
<label for="FirstName">First name:</label>
<input type="text" id="FirstName" name="FirstName" value="John">
<label for="LastName">Last name:</label>
<input type="text" id="LastName" name="LastName" value="Doe">
</form>
// Grid
@(Html.Kendo().Grid<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()
.Filterable()
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("Orders_Read", "Grid").Data("dataHandler"))
)
)