This is a migrated thread and some comments may be shown as answers.

Dependency injection into a GridController with function with an datasource parameter, causes function to not be able reached

1 Answer 93 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 11 Feb 2021, 08:07 AM

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

 

1 Answer, 1 is accepted

Sort by
0
Erik
Top achievements
Rank 1
Veteran
answered on 12 Feb 2021, 11:12 AM

Hi again,

 

This issue was resolved. Apparently, (but not sure) having an other controller, that had a function with a similar name and parameters caused the AJAX call to not be able to be made. When i removed the controller and cleaned solution Dependency injection worked flawlessly. 

 

Cheers Erik

Tags
General Discussions
Asked by
Erik
Top achievements
Rank 1
Answers by
Erik
Top achievements
Rank 1
Veteran
Share this question
or