Serializing Model to Query String
Can a model object be serialized into a query string? I don't know if this is possible, but if not, what is the way to do it?
<% Html.RenderAction("Grid", "Grid", new { gridModel= ViewData["model"]}); %>
The model contains about 20 properties, and creating a query with them separately will be difficult and look very ugly. so what are my alternatives?
a source to share
To answer directly, you can use something like JSON.NET to serialize it to ASCII and then base64 encode it.
However, there are very real limits on the amount of data you can include in a query string, and I wouldn't do that.
The closest I can think of is to create a GUID, use that GUID as the key to store the object in the session, and then pass the RenderAction to the GUID. This action will take the object out of the session and then remove it from the session.
Fast pseudocode (not even guaranteed to compile, much less work)
var _requestKey = Guid.NewGuid();
Session[requestKey] = gridModel;
Then on the other hand:
var gridModel = Session[requestKey] as GridModelType;
Session[requestKey] = null;
a source to share