Headers
As of the Telerik UI for ASP.NET Core R3 2019 release, you can set request headers by using the Headers
configuration option of the DataSource.
The following example demonstrates how to use the Headers
option to set a request header.
@(Html.Kendo().DataSource<OrderViewModel>()
.Name("myDataSource")
.Ajax(d => d.Read(r => r.Action("ReadOrders", "Home").Headers(new { header1 = "test" })))
)
<script>
myDataSource.read(); // The header will be set in the request that is sent to the HomeController ReadOrders action.
</script>
<kendo-datasource name="myDataSource" type="DataSourceTagHelperType.Ajax">
<transport>
<read url="@Url.Action("ReadOrders", "Home")" headers='new Dictionary<string,string> { ["header1"] = "test" }'/>
</transport>
</kendo-datasource>
<script>
myDataSource.read(); // The header will be set in the request that is sent to the HomeController ReadOrders action.
</script>
public IActionResult ReadOrders([DataSourceRequest]DataSourceRequest request)
{
// Get the request header "header1".
var Header1Value = Request.Headers["header1"];
// Orders can be IQueriable or IEnumerable.
return Json(orders.ToDataSourceResult(request));
}