Using the generic type 'DataTablesJsonResult<TDataType>' requires 1 type arguments error
tseward opened this issue · comments
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?
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);
}
}