Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a web app (ASP MVC2) where some forms can be accessed via multiple routes, initially once a form was complete a user was kicked back to a default page for that form rather than the page they entered it from.

Now I'm redesigning a sizable area I want to address this, I want a solution that is easy to add in. I have a couple of ideas but I'm not sure which to go with, I do know that I want it to be "invisible" (ie not touching my URLs).

So I'm thinking either:

I could have hidden fields for the referrer page on the forms.

Alternatively I could use TempData and have an attribute that handles checking and adding the referrer URL (this would likely include a string for each of the different pathways so that a user could have 2 different forms open and not have the referrers interfere).

The problem with the form value is that it would require putting non-model related fields in each of the views and would break if there's ever any GET requests in the workflow. it would also require manually handling this property in each view and action.

The TempData+attribute approach would be a much neater way to apply this but it's possible for powerusers who are doing many things at once to have conflicting referrers for the same forms.

I'm leaning towards the latter approach as it's more elegant and easier to keep track of as I don't see there being many of the edge cases where it gets overridden but I'm worried about the user experience for if it does happen. Is the trade off worth it?

share|improve this question
add comment

1 Answer

It is not clear to me what technology you are using for this so I will try to answer generically.

It sounds like users can have the form open more than once (new window or multiple tabs) launched from different contexts or more than once from the same context. This would make using session variables an issue especially with your concern of a get removing form variables from the page.

You may instead want to look at creating the form as a template (User Control in .NET) and including it in a page for each of the contexts where it is used. The parent page could have a single static variable that holds the value for the context. When processing get the values for from the form and the context from the parent page the form is in and on success redirect back to the appropriate location for the context. This of course assumes that the route and redirect you talk about can be tracked with one variable. That variable plus information on the form could also be used for various return locations.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.