<p>So I'm embarking on an <code>ASP.NET MVC</code> project and while the experience has been a good one overall, I'm not quite as pleased with the spaghetti mess that my controllers have become. I've looked around online (CodeCampServer, etc...) and they all seem to suffer the same issue wherein controller methods violate SRP (single responsibility principle) pretty consistently - such as a controller method that simply renders the view if the request is a <code>GET</code> but updates the <code>model</code> if it's a <code>POST</code>. Now I've got controller methods responsible for multiple logical routes throughout the application - say it checks for which <code>button</code> was clicked on the form and acts accordingly. I could redirect each button click to a different form action using JavaScript, but something doesn't feel right there either... The other big issue is the proliferation of magic <code>strings - ViewData["foo"] = blah;</code> Long story short, how do you guys <code>structure</code> your <code>controller</code> logic? One giant model object per view? Lots of little <code>controller methods</code> and <code>JavaScript</code> is the router? My goal is maintainable code - as features get piled on I'm starting to slide down that slippery slope...</p>

[{'answer_id': 36253, 'author': 'Brad Wilson', 'author_id': 1554, 'author_profile': 'https://Stackoverflow.com/users/1554', 'pm_score': 4, 'selected': True, 'text': '<p>ASP.NET Preview 5 (available on <a href="http://www.codeplex.com/aspnet" rel="noreferrer">CodePlex</a>) has an answer for this: the [AcceptVerbs] attribute. Phil Haack has a <a href="http://haacked.com/archive/2008/08/29/how-a-method-becomes-an-action.aspx" rel="noreferrer">blog post</a> discussion how it\'s used.</p>\n\n<p>As for the view data magic key question, it\'s an interesting problem. If you think of a view as being a bunch of semi-independent components (especially in light of the new partial view support), then making a strongly-typed model becomes less ideal, as the several pieces of the view should be relatively independent of one another.</p>\n'}, {'answer_id': 286872, 'author': 'Andrew Harry', 'author_id': 30576, 'author_profile': 'https://Stackoverflow.com/users/30576', 'pm_score': 0, 'selected': False, 'text': "<p>How are different people handling this issue?  I know that i just spent a couple hours reviewing the jumble inside of the model folder.  I'm finding creating folders is helpful in reducing the visual clutter, using matching namespaces helps alot too.</p>\n\n<p>But my controllers are monoliths at the moment.  the trouble is that i've been focused on learning to this point in the project (still lots to sort out as well).</p>\n\n<p>I'm getting a good handle on MVC now, so it is time to review the complexity and consider modifying the controllers up into better named and cleaner functions.</p>\n\n<p>Are other people breaking their controllers up into sub controllers? (If there is such a thing)</p>\n"}]
['https://Stackoverflow.com/questions/36197', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2646/']