Long story short, im trying to implement dependency injection into a grid controller. The project i use is a .NET CORE Application using the Telerik UI template.
The problem is that i cannot make an ajax call to function inside my grid controller aslong as i do dependency injection. If i remove Constructor with the provided dependency injections it works fine.
In the view that i make an ajax call looks like this
<div class="row">
<div class="col-12">
<kendo-grid name="VehicleHome" height="550">
<columns>
<column field="Id" title="ID">
<filterable enabled="false"></filterable>
</column>
<column field="Name" title="Namn" />
</columns>
<scrollable enabled="true" />
<sortable enabled="true" />
<pageable enabled="true" />
<filterable enabled="true" />
<datasource type="DataSourceTagHelperType.Ajax" page-size="20">
<transport>
<read url="@Url.Action("VehicleHome_Read", "VehicleHome")" />
</transport>
</datasource>
</kendo-grid>
</div>
</div>
And the controller and function i make an call to like this:
public class VehicleHomeController : Controller
{
private readonly IVehicleHomeService _vehicleHomeService;
private readonly IVehicleService _vehicleService;
public VehicleHomeController(IVehicleHomeService vehicleHomeService, IVehicleService vehicleService)
{
this._vehicleHomeService = vehicleHomeService;
this._vehicleService = vehicleService;
}
public ActionResult VehicleHome_Read([DataSourceRequest] DataSourceRequest request)
{
var result = Enumerable.Range(0, 50).Select(i => new VehicleHomeViewModel()
{
Id = i * i,
Name = "Vehicle Home " + i
});
var dsResult = result.ToDataSourceResult(request);
return Json(dsResult);
}
}
1. As u see, im not even using the dependencies that is passed through the constructor. Still this causes the function to not be accessed by the ajax call.
2. If i remove the constructor and the interface i can access it. How Come?
Thankful for answers