1

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?

Darren Lewis
  • 8,338
  • 3
  • 35
  • 55
  • we had a similar situation recently and after an exhuastive meeting with the stakeholders we concluded that too much effort was going to be required to exclude javascript. when the costs and workarounds were explored it was just 'easier' to make js inclusion a requirement for the app to be used. we just included the – jim tollan Sep 25 '10 at 08:54
  • Jim - I think we're coming to the same conclusion. I'm seeing this pan out the same as full W3C Accessibility compliance. Everyone wants it until you break down the costs! – Darren Lewis Sep 25 '10 at 16:48
  • 1
    Daz - unfortunately, you soon discover the boundary between ideal and idealistic. personally, i hate that 'we' have to box stuff in but on a personal level, I find it liberating that 'one' can implement an agreed compromise that just gathers momentum (we've now got said adverse company fwding links to 'good' jquery 'tricks'). Since having stakeholder buy-in to js, we've progressed at a rate of knots - especially as we have a 'department' that deals exclusively in jquery 'additives'. bottome line - it's the 'flow'. your own mileage may vary, but i think pragmatism is key in this (non) debate. – jim tollan Sep 25 '10 at 20:25
  • someone reach that here: http://stackoverflow.com/questions/8541821/how-to-simplify-my-statefull-interlaced-modal-dialogs-in-asp-net-mvc –  Jan 24 '12 at 16:32
  • as for me, "classic" asp.net web forms are much better suited for javascript-less web apps. – XanderMK Apr 17 '14 at 17:33

2 Answers2

2

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: How can I change the action a form submits to based on what button is clicked in ASP.NET MVC?
Community
  • 1
  • 1
eglasius
  • 35,831
  • 5
  • 65
  • 110
  • 1
    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? – Darren Lewis Sep 24 '10 at 16:21
  • 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 Sep 24 '10 at 16:32
0

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
  • 29,592
  • 16
  • 81
  • 103
  • 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. – Darren Lewis Sep 24 '10 at 15:37
  • I understand your problem, I'm suggesting you remove the postcode lookup button and only add it via Javascript. – roryf Sep 24 '10 at 15:49