Base solution for your next web application
Open Closed

problem using AddJsonOptions in Startup.cs ConfigureServices #3925


User avatar
0
panic created

Hello, If I add then below line of code in method ConfigureServices (in Startup.cs), the system cannot login and cannot render any records in screens like users, languages. I had to add this line of code as it is recommended to do so when you use Kendo UI for Asp .Net Core. If i remove this line of code then there is no problem. Can you explain why this is happening? Many thanks,

P.

    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        //MVC
        services.AddMvc(options =>
        {
            options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
        }).<ins>AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());</ins>

        // Add Kendo UI services to the services container
        services.AddKendo();

        var identityBuilder = IdentityRegistrar.Register(services);
            
        //Identity server
        if (bool.Parse(_appConfiguration["IdentityServer:IsEnabled"]))


1 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    MVC uses camelCase names by default. This matches most JSON naming conventions, including ASP.NET Zero.

    Kendo still uses PascalCase, thus the use of DefaultContractResolver. To use Kendo, define this in your ControllerBase:

    public abstract class MyControllerBase : AbpController
    {
        protected readonly JsonSerializerSettings KendoSerializerSettings = new JsonSerializerSettings()
        {
            ContractResolver = new DefaultContractResolver()
        };
    }
    

    and return this in Kendo-specific methods:

    public class MyController : MyControllerBase
    {
        public JsonResult GetAll([DataSourceRequest] DataSourceRequest request)
        {
            var result = new DataSourceResult();
            return Json(result, KendoSerializerSettings);
        }
    }