Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Using the generic type 'DataTablesJsonResult<TDataType>' requires 1 type arguments error #92

Open
ghost opened this issue Sep 4, 2022 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 4, 2022

I'm attempting to upgrade a project from .NET Core 3.1 to 6.0 and using [3.0.0-preview.19] of DataTables.AspNet.Core and DataTables.AspNet.AspNetCore.

A new error popped up on the upgrade and I'm not quite sure what it is asking for. My code that worked with .NET 3.1 and a previous 2.x package looks like this:

        public DataTablesJsonResult DataTablesGet([ModelBinder(typeof(DataTables.AspNet.AspNetCore.ModelBinder))] IDataTablesRequest requestModel)
        {
            if(requestModel == null)
            {
                return new DataTablesJsonResult(null, true);
            }

[...]
            var dtResponse = DataTablesResponse.Create(requestModel, totalCount, filteredCount, data);
            return new DataTablesJsonResult(dtResponse, true);
        }
    }

This error is created on both DataTablesJsonResult usages and the DataTableResponse.Create use. What am I missing?

@nlarion
Copy link

nlarion commented Nov 9, 2022

I had the same problem, and I couldn't get the DataTablesResponse() constructor to return a valid response even after doing this:

    var something = new DataTablesJsonResult<YourDataType>(dataTable);
    await something.ExecuteResultAsync(this.ControllerContext);
    return something;

I ended up changing the return type to a JsonResult. you should be able to get it to work with this

        using Microsoft.AspNetCore.Mvc;
        public JsonResult DataTablesGet([ModelBinder(typeof(DataTables.AspNet.AspNetCore.ModelBinder))] IDataTablesRequest requestModel)
        {
            if(requestModel == null)
            {
                return new JsonResult(null);
            }

[...]
            var dtResponse = DataTablesResponse.Create(requestModel, totalCount, filteredCount, data);
            return new JsonResult(dtResponse);
        }
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant