Questions tagged [controller]

A controller is responsible for executing a sequence of instructions in response to some stimulus (maybe a command, action, or event). This is often used in conjunction with the Spring or model-view-controller tags.

A controller is responsible for executing a sequence of instructions in response to some stimulus (maybe a command, action, or event). It may be used to refer to the controller portion of the MVC (Model-View-Controller) pattern, or a general handler for actions and events that orchestrates a response. It may also refer to the Spring annotation @Controller.

As it can refer to a number of different things, this tag is best used in conjunction with other tags. So, if you're referring to the Spring @Controller annotation, use the Spring tag in conjunction with this one. If you're referring to the general MVC controller, use the model-view-controller tag.

15429 questions
642
votes
14 answers

RedirectToAction with parameter

I have an action I call from an anchor thusly, Site/Controller/Action/ID where ID is an int. Later on I need to redirect to this same Action from a Controller. Is there a clever way to do this? Currently I'm stashing ID in tempdata, but when you…
Eric Brown - Cal
  • 13,058
  • 11
  • 52
  • 89
466
votes
19 answers

Can an ASP.NET MVC controller return an Image?

Can I create a Controller that simply returns an image asset? I would like to route this logic through a controller, whenever a URL such as the following is requested: www.mywebsite.com/resource/image/topbanner The controller will look up…
Jonathan
  • 29,612
  • 37
  • 126
  • 201
407
votes
14 answers

Downloading a file from spring controllers

I have a requirement where I need to download a PDF from the website. The PDF needs to be generated within the code, which I thought would be a combination of freemarker and a PDF generation framework like iText. Any better way? However, my main…
MilindaD
  • 6,733
  • 9
  • 37
  • 55
328
votes
25 answers

Multiple types were found that match the controller named 'Home'

I currently have two unrelated MVC3 projects hosted online. One works fine, the other doesn't work, giving me the error: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this…
Only Bolivian Here
  • 32,571
  • 60
  • 151
  • 250
316
votes
6 answers

How to create separate AngularJS controller files?

I have all of my AngularJS controllers in one file, controllers.js. This file is structured as follows: angular.module('myApp.controllers', []) .controller('Ctrl1', ['$scope', '$http', function($scope, $http) { }]) .controller('Ctrl2',…
Beebunny
  • 3,949
  • 3
  • 19
  • 32
308
votes
6 answers

How do I create a simple 'Hello World' module in Magento?

How can the following be accomplished in Magento? Display a "Hello World" message using a controller/view/model approach. So, if I went to http://example.com/myController it would show the string 'Hello World'. Being able to show this string within…
Click Upvote
  • 235,452
  • 251
  • 553
  • 736
295
votes
10 answers

Allow multiple roles to access controller action

Right now I decorate a method like this to allow "members" to access my controller action [Authorize(Roles="members")] How do I allow more than one role? For example the following does not work but it shows what I am trying to do (allow "members"…
codette
  • 11,303
  • 9
  • 35
  • 38
216
votes
5 answers

Can I get the name of the current controller in the view?

Is there a way to figure out what the current controller is from within the view? For an example of why I would want to know this: if several controllers share the same layout, I may have a part in the layout ERB file where I want to highlight the…
Dan Tao
  • 119,009
  • 50
  • 280
  • 431
189
votes
13 answers

Get controller and action name from within controller?

For our web application I need to save the order of the fetched and displayed items depending on the view - or to be precise - the controller and action that generated the view (and the user id of course, but that's not the point here). Instead of…
Rob
  • 10,600
  • 13
  • 51
  • 86
120
votes
4 answers

ASP.NET MVC: Is Controller created for every request?

Very simple question: Are controllers in ASP.NET created for every HTTP request, or are they created at application startup and reused throughout requests? Will the controller be created only for a particular HTTP request? If my previous assumptions…
Rasto
  • 17,000
  • 40
  • 141
  • 232
118
votes
14 answers

Is it possible to determine whether ViewController is presented as Modal?

Is it possible to check inside ViewController class that it is presented as modal view controller?
lukewar
  • 2,665
  • 2
  • 17
  • 16
115
votes
2 answers

Which is better, return "ModelAndView" or "String" on spring3 controller

The way of return ModelAndView @RequestMapping(value = "/list", method = RequestMethod.GET) public ModelAndView list( @UserAuth UserAuth user, ModelAndView mav) { if (!user.isAuthenticated()) { …
gentlejo
  • 2,158
  • 4
  • 22
  • 30
111
votes
4 answers

Init method in Spring Controller (annotation version)

I'm converting a controller to the newer annotation version. In the old version I used to specify the init method in springmvc-servlet.xml using: How can I specify the init…
Krt_Malta
  • 8,695
  • 17
  • 50
  • 89
103
votes
7 answers

Multiple controllers with AngularJS in single page app

I want to know is how to use multiple controllers for a single page application. I have tried to figure it out and I've found questions very similar to mine, but there is just a ton of different answers solving a specific problem where you end up…
user2539369
97
votes
6 answers

ASP.NET MVC - Should business logic exist in controllers?

Derik Whitaker posted an article a couple of days ago that hit a point that I've been curious about for some time: should business logic exist in controllers? So far all the ASP.NET MVC demos I've seen put repository access and business logic in the…
Kevin Pang
  • 39,694
  • 37
  • 117
  • 169
1
2 3
99 100