tags:

views:

66

answers:

3

Hi everyone!

I have a View that receives a List of an object and for each object in this list I generate a Partial View.

It's a seach result, such as Google. Each result will be wrapped in a form and each result will have its "save" post button.

So, when I post a form, I will lead user to another page where he will confirm the result he chose.

Some itens of the result I can save them to hidden fields and pass them in a FormCollection to this other page.

But, I was wondering if there's a way that I could pass this result object via post, in stead of creating hidden fields (?).

Thanks a lot!!

+2  A: 

Hmmm, I think the answer is probably "no", but have a look at TempData and see if that might do the trick.

mgroves
+1  A: 

How about storing them in the database and assigning a resource identifier such as a GUID to the whole thing and only posting that?

DrJokepu
+1  A: 

You could write a custom serialize method in JS and then stuff the serialized object in a hidden field, like this:

 <script type="text/javascript">
   object; // from your search
   var serialized = serialize(object);
   $("#objectHidden").val(serialized);
 </script>

Then on the ASP.NET MVC side, you would write a custom Deserialize() method and deserialize it into the object you want:

 public ActionResult foo(FormCollection form)
 {
   MyObject object = MyObject.Deserialize(form["objectHidden"]);
 }

This code is quick and dirty, but I hope it conveys the idea.

cdmckay
But, how can I get in JS the object?
AndreMiranda
I'm sorry, I don't understand what you're asking. Where are you trying to bring this object? From JavaScript form to C#? Or from JS to C# to JS?
cdmckay