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

Grid read action misuse the ApiController

3 Answers 364 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Veteran
Iron
Iron
Chris asked on 12 Nov 2019, 04:08 AM

HI

Why the Grid read action (include javascript grid.dataSource.read() function use "api" url ???

ERROR : POST http://localhost:31466/api/AppM010/GetSomeList 415 (Unsupported Media Type)

View

.Read(read => read.Action("GetSomeList", "AppM010").Data("..."))

Javascript

grid.dataSource.read() 

There have Controller/ApiController with the same class/method name and different namespace in application : 

  namespace App1.ApiControllers
  {
    [ApiController]
    [ProducesAttribute("application/json"]
    [Route("api/{controller}/{action}")]
    public class AppM010Controller : BaseController
    {
        public AppM010Controller()
        {
        }

        [HttpPost]
        public IList<TSomeView> GetSomeList(...)
        {

  namespace App1.Controllers
  {
    public class AppM010Controller : Controller
    {
        public AppM010Controller()
        {
        }

        public ActionResult GetSomeList([DataSourceRequest]DataSourceRequest request, ...)
        {


*Don't ask me change the Controller/ApiController or method name.

Nobody knows there have the [ApiController] attribute for ApiController ?? 
I don't want any component action use the ApiController.

I think the component action got the wrong controller via action name only.
Not only the Grid, othere component is the same.

Fix this BUG as soon as possible, please.

Best regards

Chris

 

 


3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 14 Nov 2019, 06:23 PM

Hello,

The reason why "api" is added to the url is because a web api transport is used for a transport option of the DataSource definition of the Kendo UI Grid for ASP.NET Core. Please check the highlighted part of the code below: 

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
	  .Name("grid")
	  .Columns(columns =>
	  {
		  columns.Bound(p => p.ProductName);
		  columns.Bound(p => p.UnitPrice).Width(100);
		  columns.Bound(p => p.UnitsInStock).Width(100);
		  columns.Bound(p => p.Discontinued).Width(100);
		  columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
	  })
	  .ToolBar(tools =>
	  {
		  tools.Create();
	  })
	  .Sortable()
	  .Pageable()
	  .Filterable()
	  .DataSource(dataSource =>
		  dataSource
			.WebApi()
			.Model(model =>
			{
				model.Id(p => p.ProductID);
			})
.....		
	  )
)

You can use Ajax instead if the web api transport does not meet your needs.

 

Regards,
Boyan Dimitrov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Chris
Top achievements
Rank 1
Veteran
Iron
Iron
answered on 15 Nov 2019, 01:46 AM

HI

I forgot to note that my applicaton NEVER NEVER NEVER use dataSource.WebApi() method explicitly : 

    .DataSource(dataSource =>
    {
      dataSource
        .Ajax()
        .Batch(true)
        .Model(model =>
        {
          ...
        })
        .ServerOperation(false)
        .Events(events =>
        {
          ...
        })
        .Read(read => read.Action("XXXX_Read", "AppM010").Data("..."))
        ...;
    })

Or Grid.DataSource will use WebApi() method implicitly ??? How to avoid that ?

Please test the component with .NET Core Web MVC Application COMPLETELY.

Best regards

Chris

 

 

0
Boyan Dimitrov
Telerik team
answered on 19 Nov 2019, 04:35 PM

Hello,

 

When I test locally with similar back-end configuration and Kendo UI Grid for ASP.NET Core in the view it works fine. I would suggest to try to rename the controller name just for testing purposes and let us know how that worked. 

If it is possible could you please send us a runnable sample project (controllers can return only static data) that replicates the problem. This way we can investigate the specific case. In order to attach a project you need to submit a support ticket instead of forum thread.

 

Regards,
Boyan Dimitrov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Veteran
Iron
Iron
Answers by
Boyan Dimitrov
Telerik team
Chris
Top achievements
Rank 1
Veteran
Iron
Iron
Share this question
or