views:

119

answers:

2

I have a website which is basically a single page containing a bunch of dynamic content. In normal operation the user should never leave this page. To handle/report certain errors though, I need to redirect to an error page. So on the error page I want to provide a link back to the normal page which provides the app the information required to rebuild all the dynamic content which was previously open.

I think I can rebuild the page by parsing the querystring with javascript and reloading dynamic content. I'm not sure if this is the best way, but I've got it working. So href in the link on my error page needs to look something like:

MySite/MyController/MyAction?1,5,8,9

where the numbers in the querystring basically indicate the Id's of content sections to load in on document.ready.

I'm now stuck on how to generate this link though. I think I need to pass these numbers into the controller somehow, so the controller can pass them into the error view which will then generate the "back" link.

I have a standard html form for uploading a file:

using (Html.BeginForm("MyAction", "MyController", 
                       FormMethod.Post, 
                       new { enctype = "multipart/form-data" }))

                       { /* ... */ }

I then have a button which calls the jQuery .submit() method on the form.

So, the question, when I click on the button which submits the form, how can I attach the additional data so I can access it in my controller?

Hope that's clear, if not let me know and I can provide more detail. Thanks.

Edit: It occured to me that I could submit this information with a hidden field in the form. I'll try that if I can't find a better way, but I'd like a more generic solution if possible as I have a number of forms on the page and ideally I'd like this data available to any/all of them.

A: 

your url should be biult just before sending the form with .submit() not in Html.BeginForm tag.... i can't see the problem over here... what exactly you are dealing with?

Jack
I don't think it's possible to specify a URL in the submit method. Could you explain more please?
fearofawhackplanet
A: 

I know this is not quite what you asked but instead of going through the hassle of redirecting the user in the first place why don't you show a modal window (a jquery based one) that contains an iFrame. The iFrame href can be determined by the calling page and can show the error page.

Not sure if this helps but I have used this technique and found that I do not need to worry about getting the user back to the place where they started from. Additional to this you will not need to rebuilding/reloading the orignal content as it will still be on the calling page.

*EDIT* After reading your comments maybe you could do the following...

  1. On the link click - open up a modal popup pointing to an iframe.
  2. The iframe calls the action on the controller to download the file.
  3. The view could say "Downloading file... please wait, click here to close etc."
  4. If the action throws the error then redirect to the error page as normal as it is within the iframe modal popup.

This way you do not need to leave the current calling page.

Rippo
That would be my prefered approach, but I don't think it's possible. Actually I made a slight mistake in my question as I'm not ajaxing the form. See my earlier question here which explains why I'm displaying a new error page: http://stackoverflow.com/questions/3229280/asp-net-mvc-how-can-i-return-an-error-from-a-file-download-action-without-leaving
fearofawhackplanet
I see, so basically you have a link to "download a file", if this throws an error then you want to show the error somehow. If no error occurs you want the file to get downloaded.
Rippo
@Rippo: yes that's correct. And if I have to show the error on a new page, I want a link that effectively recovers the previous page in whatever state it was before the error. Note though that my previous question was somewhat simplified, as I'm using a file browser dialog (form) and not just a static link.
fearofawhackplanet