views:

69

answers:

2

We're developing a site initially without javascript for maximum support with the intention of layering js functionality over the top. The problem we have is where a single page has 2 or more pieces of functionality (as an example a screen to capture personal details that includes a postcode lookup for address). With no ability to change the postback on either the complete form submission or a postback to lookup a postcode we end up with a single controller action that does both. This doesn't feel great as we end up with an Index Action doing more than one thing. Given a js enabled client this would be separated out nicely into separate actions.

I was wondering if anyone else has faced this issue of producing a javascript free ASP.MVC site and what pattern you used to overcome Controller Action bloat as we're calling it?

A: 

I've done this specific example (postcode lookup) a couple of times recently and made the decision that users with no Javascript just wouldn't get that functionality. They would get the full address form, which I would then hide and replace with postcode and lookup link via Javascript.

Not an answer to your overall question, but perhaps something to think about.

roryf
In our case the user also gets the full address which are part of the same HTML Form as their personal details so they both get posted back as one when the form is complete.The form then has two buttons on, one for full form submission and one for postcode lookup. Our problem is that with no javascript we (as far as we know) cannot control the controller action that gets executed so our Index action has to do more than one thing. Hope that makes sense.
Daz Lewis
I understand your problem, I'm suggesting you remove the postcode lookup button and only add it via Javascript.
roryf
+2  A: 

A couple options.

  1. use a separate form for the postcode lookup, then render the same view you already had / with whatever different info. This can't be nested
  2. identify the button used to post the form / similar to this answer: http://stackoverflow.com/questions/1976670/how-can-i-change-the-action-a-form-submits-to-based-on-what-button-is-clicked-in/1976711#1976711
eglasius
1) If I have a separate form and assume the postcode lookup is on the second. Then all the currently entered data on the first form will be lost on postback of the second.2) This is what we're doing already it just seems wrong to have to handle different concerns in the same controller action. We currently have an if statement to determine the button clicked and fire off to the appropriate Action that will be used when we implement the javascript. It just doesn't seem very elegant. Perhaps this is just the price we pay server side for a js free client?
Daz Lewis
re 1, yes. It'd have to be clearly presented as step 1 of the process or something like that. re 2 if you are posting with the same form and no js is involved to change it you are deciding to post to the same action, so y, its the price to pay. Previous said, you could have some convention and generalize it with a custom route handler, that changes the action method to be called. If its just this time, I wouldn't bother, but if it happens all around I would definitely go for it.
eglasius