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.

16598 questions
712
votes
16 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
  • 14,135
  • 12
  • 58
  • 97
478
votes
20 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
  • 32,202
  • 38
  • 137
  • 208
452
votes
15 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
  • 7,533
  • 9
  • 43
  • 63
400
votes
30 answers

Laravel 5 Failed opening required bootstrap/../vendor/autoload.php

I have recently installed Laravel 5 via Composer. I tried creating a new controller using Artisan and got the following error. Am I missing something? bootstrap/../vendor/autoload.php. Failed to open stream: No such file or directory. The "vendor"…
Scott
  • 5,074
  • 3
  • 16
  • 13
343
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
  • 35,719
  • 63
  • 161
  • 257
325
votes
13 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
  • 12,343
  • 9
  • 37
  • 38
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
  • 4,190
  • 4
  • 24
  • 37
311
votes
5 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…
Ali
  • 261,656
  • 265
  • 575
  • 769
235
votes
17 answers

Access Controller method from another controller in Laravel 5

I have two controllers SubmitPerformanceController and PrintReportController. In PrintReportController I have a method called getPrintReport. How to access this method in SubmitPerformanceController?
Iftakharul Alam
  • 3,201
  • 4
  • 21
  • 33
231
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
  • 125,917
  • 54
  • 300
  • 447
210
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
  • 11,492
  • 14
  • 59
  • 94
188
votes
11 answers

How to call another controller Action From a controller in Mvc

I need to call a controller B action FileUploadMsgView from Controller A and need to pass a parameter for it. Its not going to the controller B's FileUploadMsgView(). Here's the code: ControllerA: private void Test() { try { //some codes…
user2156088
  • 2,350
  • 5
  • 20
  • 24
140
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,204
  • 47
  • 154
  • 245
125
votes
5 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
  • 9,265
  • 18
  • 53
  • 91
119
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,715
  • 3
  • 19
  • 16
1
2 3
99 100