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
61
votes
2 answers

ASP.NET MVC: returning plaintext file to download from controller method

Consider the need to return a plain-text file from a controller method back to the caller. The idea is to have the file downloaded, rather than viewed as plaintext in the browser. I have the following method, and it works as expected. The file is…
p.campbell
  • 91,713
  • 61
  • 243
  • 314
60
votes
5 answers

In Rails when a resource create action fails and calls render :new, why must the URL change to the resource's index url?

I have a resource called Books. It's listed as a resource properly in my routes file. I have a new action, which gives the new view the standard: @book = Book.new On the model, there are some attributes which are validated by presence, so if a…
rcd
  • 1,300
  • 1
  • 14
  • 27
59
votes
10 answers

Why is it that "No HTTP resource was found that matches the request URI" here?

I have code in my controller like so: [Route("api/deliveryitems/InsertIntoPPTData/{stringifiedRecord}")] ...and I'm calling it via Postman like so: …
B. Clay Shannon
  • 1,055
  • 124
  • 399
  • 759
59
votes
5 answers

How to access plain json body in Spring rest controller?

Having the following code: @RequestMapping(value = "/greeting", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) @ResponseBody public String greetingJson(@RequestBody String json) { System.out.println("json =…
Marcel Overdijk
  • 9,358
  • 15
  • 59
  • 100
58
votes
7 answers

post and get with same method signature

In my controller I have two actions called "Friends". The one that executes depends on whether or not it's a "get" versus a "post". So my code snippets look something like this: // Get: [AcceptVerbs(HttpVerbs.Get)] public ActionResult Friends() { …
codette
  • 11,303
  • 9
  • 35
  • 38
57
votes
3 answers

What does "The type T must be a reference type in order to use it as parameter" mean?

I'm trying to create a generic controller on my C#/MVC/Entity Framework application. public class GenericRecordController : Controller { private DbSet Table; // ... public action() { // ... …
Daniel Santos
  • 8,957
  • 15
  • 65
  • 139
53
votes
2 answers

How to tell which format a controller has resolved to render

In a rails controller action with the following code: respond_to do |format| format.json{ render :json=> {:status => 200, :response=>@some_resource} } format.html { redirect_to(some_resource_path)} end How can I log the format the controller…
Undistraction
  • 38,727
  • 46
  • 165
  • 296
51
votes
8 answers

how to create global function that can be accessed from any controller and blade file

I have two controller file homecontroller and backendcontroller. What is the best way to create global function and access it from both files? I found here Arian Acosta's answer helpful but I wonder if there is an easiest way. I would appreciate…
Johnny
  • 1,415
  • 4
  • 22
  • 36
48
votes
2 answers

How to call ApplicationController methods from ApplicationHelper

I want to provide csv links in a view and I placed the csv generating code in ApplicationHelper. However I'm getting this error: undefined method `send_data' for #<#:0x0000010151a070> referencing this: send_data content,…
David
  • 7,132
  • 6
  • 38
  • 61
47
votes
2 answers

Default Routes in a Backbone.js controller?

I want to set a default route for my backbone.js controller. Currently I do it like so: class DealSearchController extends Backbone.Controller routes: 'list' : 'showListView' 'photos' : 'showPhotoView' 'map' :…
Martin Wawrusch
  • 780
  • 1
  • 5
  • 12
47
votes
6 answers

How to get list of all routes of a controller in Symfony2?

I have a controller which implements all routes/URL(s). I had the idea to offer a generic index over all help-pages. Is there a way to get all routes defined by a controller (from within a controller) in Symfony2?
Sammy
  • 1,026
  • 1
  • 13
  • 26
46
votes
11 answers

Mockito Exception - when() requires an argument which has to be a method call on a mock

I have a very simple test case that is using Mockito and Spring Test framework. When I do when(pcUserService.read("1")).thenReturn(pcUser); I get this exception. org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires…
jsf
  • 2,511
  • 8
  • 28
  • 33
46
votes
4 answers

How to test a Controller Concern in Rails 4

What is the best way to handle testing of concerns when used in Rails 4 controllers? Say I have a trivial concern Citations. module Citations extend ActiveSupport::Concern def citations ; end end The expected behavior under test is that any…
jelder
  • 1,673
  • 1
  • 16
  • 17
46
votes
4 answers

Angular JS resizable div directive

My site will have multiple sections, each of which I intend to be resizable. To accomplish this I've made a "resizable" directive, e.g.:
jayflo
  • 1,055
  • 1
  • 12
  • 21
46
votes
3 answers

AngularJS: How to pass arguments/functions to a directive?

Look at this Fiddle, what do I have to change, that the expressions in the template get evaluated using the arguments I defined in the HTML? The SAVE-button should call the blabla()-function of the controller, since I pass it? var myApp =…
user1879408
  • 1,768
  • 3
  • 16
  • 26