Skip to content

Commit 9f72a4e

Browse files
committed
ModelBindingFix
1 parent 28c4d08 commit 9f72a4e

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

Mvc.JQuery.DataTables.AspNetCore.Example/Controllers/HomeController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Mvc.JQuery.DataTables.Models;
55
using Mvc.JQuery.DataTables.Serialization;
66
using System.Linq;
7+
using System.Reflection;
78

89
namespace Mvc.JQuery.DataTables.Example.Controllers
910
{
@@ -109,5 +110,10 @@ public DataTablesResult<UserTableRowViewModel> GetUsers([FromForm] DataTablesPar
109110
});
110111
}
111112

113+
public ContentResult EmbeddedResource()
114+
{
115+
var assembly = typeof(DataTableConfigVm).GetTypeInfo().Assembly;
116+
return Content(string.Join("|", assembly.GetManifestResourceNames().Select(r => r)));
117+
}
112118
}
113119
}

Mvc.JQuery.DataTables.AspNetCore/DataTablesModelBinder.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
1616
//TODO: Consider whether this should be pushed to a worker thread...
1717
if (columns == 0)
1818
{
19-
return Task.FromResult(BindV10Model(valueProvider));
19+
var bindV10Model = BindV10Model(valueProvider);
20+
bindingContext.Result = ModelBindingResult.Success(bindV10Model);
21+
return Task.FromResult(bindV10Model);
2022
}
2123
else
2224
{
23-
return Task.FromResult(BindLegacyModel(valueProvider, columns));
25+
var bindLegacyModel = BindLegacyModel(valueProvider, columns);
26+
bindingContext.Result = ModelBindingResult.Success(bindLegacyModel);
27+
return Task.FromResult(bindLegacyModel);
2428
}
2529
}
2630

@@ -110,7 +114,7 @@ public IModelBinder GetBinder(ModelBinderProviderContext context)
110114
throw new ArgumentNullException(nameof(context));
111115
}
112116

113-
if (!context.Metadata.IsComplexType && context.Metadata.ModelType == typeof(string)) // only encode string types
117+
if (context.Metadata.ModelType == typeof(DataTablesParam)) // only encode string types
114118
{
115119
return new DataTablesModelBinder();
116120
}

Mvc.JQuery.DataTables.AspNetCore/Extensions.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,18 @@ public static IApplicationBuilder UseMvcJQueryDataTables(this IApplicationBuilde
4949
if(settings == null)
5050
{
5151
throw new InvalidOperationException("Unable to find the required services. Please add all the required services by calling 'IServiceCollection.{}' inside the call to 'ConfigureServices(...)' in the application startup code.");
52-
}
52+
}
53+
app.UseStaticFiles();
5354

54-
app.UseStaticFiles(new StaticFileOptions
5555
{
56-
FileProvider = settings.FileProvider,
57-
});
56+
var options = new StaticFileOptions
57+
{
58+
RequestPath = "",
59+
FileProvider = settings.FileProvider
60+
};
61+
62+
app.UseStaticFiles(options);
63+
}
5864
return app;
5965
}
6066
}

Mvc.JQuery.DataTables.Common/Mvc.JQuery.DataTables.Common.csproj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard1.6;net451</TargetFrameworks>
4+
<TargetFrameworks>netstandard1.6;net451</TargetFrameworks>
55
<RootNamespace>Mvc.JQuery.DataTables.Common</RootNamespace>
66
<AssemblyName>Mvc.JQuery.DataTables.Common</AssemblyName>
77
<PackageId>Mvc.JQuery.DataTables.Common</PackageId>
8-
<PackageVersion>1.0.0</PackageVersion>
9-
<Authors>Harry McIntyre</Authors>
10-
<Description>Popular lib for using DataTables.net with IQueryable. This package contain x-platform shared code. Install either Mvc.JQuery.DataTables for MVC5 or Mvc.JQuery.DataTables.AspNetCore for AspNetCore</Description>
11-
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
12-
<PackageProjectUrl>https://github.com/mcintyre321/mvc.jquery.datatables</PackageProjectUrl>
13-
<Copyright>Harry McIntyre</Copyright>
14-
<PackageTags>jquery datatables iqueryable razor asp mvc mvc5</PackageTags>
15-
<PackageLicenseUrl>https://github.com/mcintyre321/mvc.jquery.datatables/blob/master/License.</PackageLicenseUrl>
8+
<PackageVersion>1.0.0</PackageVersion>
9+
<Authors>Harry McIntyre</Authors>
10+
<Description>Popular lib for using DataTables.net with IQueryable. This package contain x-platform shared code. Install either Mvc.JQuery.DataTables for MVC5 or Mvc.JQuery.DataTables.AspNetCore for AspNetCore</Description>
11+
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
12+
<PackageProjectUrl>https://github.com/mcintyre321/mvc.jquery.datatables</PackageProjectUrl>
13+
<Copyright>Harry McIntyre</Copyright>
14+
<PackageTags>jquery datatables iqueryable razor asp mvc mvc5</PackageTags>
15+
<PackageLicenseUrl>https://github.com/mcintyre321/mvc.jquery.datatables/blob/master/License.</PackageLicenseUrl>
1616
</PropertyGroup>
1717

1818
<ItemGroup>

Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
<PackageVersion>1.0.0</PackageVersion>
1010
<Authors>Harry McIntyre</Authors>
11-
<Description>Popular lib for using DataTables.net with IQueryable. Install this package to use with MVC5etCore</Description>
11+
<Description>Popular lib for using DataTables.net with IQueryable. Install this package to use with MVC5</Description>
1212
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1313
<PackageProjectUrl>https://github.com/mcintyre321/mvc.jquery.datatables</PackageProjectUrl>
1414
<Copyright>Harry McIntyre</Copyright>
1515
<PackageTags>jquery datatables iqueryable razor asp mvc mvc5</PackageTags>
16-
<PackageLicenseUrl>https://github.com/mcintyre321/mvc.jquery.datatables/blob/master/License.</PackageLicenseUrl> </PropertyGroup>
16+
<PackageLicenseUrl>https://github.com/mcintyre321/mvc.jquery.datatables/blob/master/License.</PackageLicenseUrl>
17+
</PropertyGroup>
1718

1819
<ItemGroup>
1920
<PackageReference Include="Microsoft.AspNet.Mvc" version="5.2.3" />

0 commit comments

Comments
 (0)