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
117
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,690
  • 4
  • 26
  • 31
112
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
  • 14,328
  • 21
  • 91
  • 174
105
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
101
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
  • 41,172
  • 38
  • 121
  • 173
98
votes
8 answers

How to rename rails controller and model in a project

I started a Rails app and everything works fine. But now, I would like to rename a controller and the associated model: I wanted to change the Corps controller to Stores and the same (without final s) for the model. Looking on google, people…
Hassen
  • 6,966
  • 13
  • 45
  • 65
97
votes
8 answers

How to pass parameters to a partial view in ASP.NET MVC?

Suppose that I have this partial view: Your name is @firstName @lastName which is accessible through a child only action like: [ChildActionOnly] public ActionResult FullName(string firstName, string lastName) { } And I want to…
96
votes
5 answers

Web API Routing - api/{controller}/{action}/{id} "dysfunctions" api/{controller}/{id}

I have the default Route in Global.asax: RouteTable.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional } ); I wanted to…
Mickael Caruso
  • 8,721
  • 11
  • 40
  • 72
93
votes
10 answers

Generate a controller with all the RESTful functions

I am trying to generate a controller with all the RESTful actions stubbed. I had read at Wikibooks - Ruby on Rails that all I needed to do was to call the generator with the controller name and I would get just that. So, I ran script/generate…
Barb
  • 957
  • 1
  • 6
  • 5
92
votes
3 answers

AngularJS custom filter function

Inside my controller, I would like to filter an array of objects. Each of these objects is a map which can contain strings as well as lists I tried using $filter('filter')(array, function) format but I do not know how to access the individual…
user2368436
  • 933
  • 1
  • 6
  • 4
88
votes
4 answers

Why we shouldn't make a Spring MVC controller @Transactional?

There are already a few questions about the topic, but no response at all really provides arguments in order to explain why we shouldn't make a Spring MVC controller Transactional. See: Transaction not working correctly - Spring/MyBatis For web MVC…
jeromerg
  • 2,997
  • 2
  • 26
  • 36
87
votes
10 answers

Is Spring annotation @Controller same as @Service?

Is Spring annotation @Controller same as @Service? I have idea about @Controller which can be used for URL mapping and invoking business logic. while @Service used to annotate service class which contains business logic. Can I use @Controller…
Ketan
  • 2,612
  • 5
  • 31
  • 44
80
votes
7 answers

asp.net mvc3: How to return raw html to view?

Are there other ways I can return raw html from controller? As opposed to just using viewbag. like below: public class HomeController : Controller { public ActionResult Index() { ViewBag.HtmlOutput = ""; return…
River
  • 1,487
  • 3
  • 15
  • 25
79
votes
7 answers

How should one unit test a .NET MVC controller?

I'm looking for advice regarding effective unit testing of .NET mvc controllers. Where I work, many such tests use moq to mock the data layer and to assert that certain data-layer methods are called. This doesn't seem useful to me, since it…
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
78
votes
6 answers

Can we pass model as a parameter in RedirectToAction?

I want to know, there is any technique so we can pass Model as a parameter in RedirectToAction For Example: public class Student{ public int Id{get;set;} public string Name{get;set;} } Controller public class StudentController :…
Amit
  • 15,217
  • 8
  • 46
  • 68
78
votes
6 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
  • 11,041
  • 17
  • 71
  • 110