0

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!!

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

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.

2 Comments

But, how can I get in JS the object?
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.