Nov 06, 2014, 2:43 PM
Best practice for returning custom paging data
Hi,
I have an MVC controller that returns a StoreResult for a grid.
StoreResult sets the Data property as well as Total. So this is typically a Paging<T> for me.
I have a particular sub class of Store that has a LOT of separate Parameters as part of the query (maybe 20! we have a complex search engine!!). In addition, I actually want to return a subclass of Paging<T> that has some other properties in addition to data and total records (so that the UI has some further information to act on as part of a single request/response, e.g. I send down a list of error messages associated with each row that is displayed in a panel above the grid).
Finally, the rows of data I have are sparsely populated so I have a lot of rows and many columns but many values are null. If I am custom serializing with Json.NET I can ignore nulls easily. However, trying to return this.Store() from an MVC Controller action, I can't see a way to pass my own instance of JsonSerializationSettings through to be used by the call to JSON.Serialize() that is called inside StoreResult.
I am thinking to achieve this I might need to do the following:
* If I am to subclass of StoreResults I would need to override ExecuteResult() to use my own instance of StoreResponse. But this also means I can then use my own serialization settings as I would need to call JSON.Serialize myself.
Does that sound right or am I complicating things and is there a better way to go about this?
I am doing all this to then compare whether ASHX, MVC Controller or Web API Controller is better from a performance (and code maintenance) point of view, for my particular purpose!
I am quite comfortable with ASHX and already have that working, for a long time, without the need for various subclasses as I can control it all. But I'd like to see whether or not there is significant performance degradation going via an MVC controller or Web API controller and what the different coding considerations are from a maintenance point of view. As our app gets more and more complex with more controllers/handlers, it starts to look inconsistent (to new comers) why sometimes we use Controllers and other times ASHX handlers, etc...! But I just want to see if there is a performance method to my madness :)
Thanks!
I have an MVC controller that returns a StoreResult for a grid.
StoreResult sets the Data property as well as Total. So this is typically a Paging<T> for me.
I have a particular sub class of Store that has a LOT of separate Parameters as part of the query (maybe 20! we have a complex search engine!!). In addition, I actually want to return a subclass of Paging<T> that has some other properties in addition to data and total records (so that the UI has some further information to act on as part of a single request/response, e.g. I send down a list of error messages associated with each row that is displayed in a panel above the grid).
Finally, the rows of data I have are sparsely populated so I have a lot of rows and many columns but many values are null. If I am custom serializing with Json.NET I can ignore nulls easily. However, trying to return this.Store() from an MVC Controller action, I can't see a way to pass my own instance of JsonSerializationSettings through to be used by the call to JSON.Serialize() that is called inside StoreResult.
I am thinking to achieve this I might need to do the following:
- Subclass StoreRequestParameters to handle the additional "extraParams" and then make this new class the action parameter
- Subclass Paging<T> so I can have additional properties I want to return when I query my search engine
- Subclass StoreResults to take my custom Paging object that can hold additional properties to return*
- Subclass StoreResponse so that my additional properties in my Paging object can be passed in the response
* If I am to subclass of StoreResults I would need to override ExecuteResult() to use my own instance of StoreResponse. But this also means I can then use my own serialization settings as I would need to call JSON.Serialize myself.
Does that sound right or am I complicating things and is there a better way to go about this?
I am doing all this to then compare whether ASHX, MVC Controller or Web API Controller is better from a performance (and code maintenance) point of view, for my particular purpose!
I am quite comfortable with ASHX and already have that working, for a long time, without the need for various subclasses as I can control it all. But I'd like to see whether or not there is significant performance degradation going via an MVC controller or Web API controller and what the different coding considerations are from a maintenance point of view. As our app gets more and more complex with more controllers/handlers, it starts to look inconsistent (to new comers) why sometimes we use Controllers and other times ASHX handlers, etc...! But I just want to see if there is a performance method to my madness :)
Thanks!
Last edited by Daniil; Nov 11, 2014 at 9:59 AM.
Reason: Opened