ALMMa / datatables.aspnet

Microsoft AspNet bindings and automatic parsing for jQuery DataTables along with extension methods to help on data queries.
MIT License
301 stars 135 forks source link

How to pass string array in AdditionalParameters response? #54

Open Tegawende opened 7 years ago

Tegawende commented 7 years ago

Hello,

I want to return additional parameters from my controllers. I enabled the response parameters according to what you said in other thread. My question is about the parser function. How can I write my parser function if I want to return a string array?

Sorry for my bad english. Thanks !

bogusz commented 7 years ago

Hi,

I had similar problem just few minutes ago (Dictonary as additional parameter value). The problem is that in ToString() method of DataTablesResponse class writes additional parameters like this: jsonWriter.WriteValue(keypair.Value);

I wanted to override this behavior, but DataTablesResponse can not be inherited, because of private constructors..

So, I copied the DataTablesResponse class implementation to my own DataTablesResponseExtended class and use this code to write addidtional parameters:

foreach (var keypair in AdditionalParameters)
{
    jsonWriter.WritePropertyName(keypair.Key, true);
    if (keypair.Value is IEnumerable)
    {
        jsonWriter.WriteRawValue(SerializeData(keypair.Value));
    }
    else
    {
        jsonWriter.WriteValue(keypair.Value);
    }
}