Category / Section
How to use the Report Viewer with camel case serializer settings application?
Published:
Updated:
If you are using the camel serializer for our application, then will have a problem in processing API result with Report Viewer. So, you have to use the default resolver for using the Report Viewer and Designer.
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
You can refer the following code snippet to resolve to set the default serializer for Report Viewer Web API with ASP.NET MVC.
public class DefaultCaseControllerConfigAttribute : Attribute, System.Web.Http.Controllers.IControllerConfiguration
{
public void Initialize(System.Web.Http.Controllers.HttpControllerSettings controllerSettings, System.Web.Http.Controllers.HttpControllerDescriptor controllerDescriptor)
{
var formats = controllerSettings.Formatters.OfType<System.Net.Http.Formatting.JsonMediaTypeFormatter>().ToList();
foreach (var format in formats)
{
controllerSettings.Formatters.Remove(format);
}
var formatter = new System.Net.Http.Formatting.JsonMediaTypeFormatter
{
SerializerSettings = { ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver() }
};
controllerSettings.Formatters.Add(formatter);
}
}
[DefaultCaseControllerConfigAttribute]
public class RreportApiController : ApiController, IReportController
{
}