tags:

views:

75

answers:

2

Hi.

Would it be possible to serialize a model object into a query string? I've no idea if this is even possible, but if not, what is the best way to do this?

<% Html.RenderAction("Grid", "Grid", new { gridModel= ViewData["model"]}); %>

The Model is containing ca 20 properties, and creating the querystring with them in individually would make it a pain to work with and it would look really ugly. so what alternatives do I have?

A: 

To answer directly, you could use something like JSON.NET to serialize it to ASCII and then base64 encode it.

However, there are very real limits on how much data you can include in the query string and I'd hesitate to do this.

The closest thing I can think of would be to create a GUID, use that GUID as a key to store the object in Session, then pass the RenderAction the GUID. That action would pull the object out of the Session and then remove it from the Session.

Quick pseudocode (not guaranteed to even compile, much less work)

var _requestKey = Guid.NewGuid();
Session[requestKey] = gridModel;

Then on the other side:

var gridModel = Session[requestKey] as GridModelType;
Session[requestKey] = null;
J Wynia
Cool. I see what you're saying. I ended up working around it and not serialize the Model, but manually enter the paramaters that's needed. Not pretty, but it works fine. Thanks for answer.
MrW
A: 

I ended up using Form for this. Wasn't as pretty and nice as I wanted, but as far as I understand the only good way I could do it.

MrW