Questions tagged [asp.net-mvc-controller]

The ASP.NET MVC framework maps URLs to classes that are referred to as controllers. Controllers process incoming requests, handle user input and interactions, and execute appropriate application logic. A controller class typically calls a separate view component to generate the HTML markup for the request.

The base class for all controllers is the ControllerBase class, which provides general MVC handling. The Controller class inherits from ControllerBase and is the default implement of a controller.

The Controller class is responsible for the following processing stages:

  • Locating the appropriate action method to call and validating that it can be called.
  • Getting the values to use as the action method's arguments.
  • Handling all errors that might occur during the execution of the action method.
  • Providing the default WebFormViewEngine class for rendering ASP.NET page types (views).
193 questions
119
votes
4 answers

ASP.NET MVC Controller Naming Pluralization

RESTful conventions indicate using plural nouns over singular objects. What is the pluralization convention for naming ASP.NET MVC controllers, i.e. ProductController or ProductsController?
91
votes
11 answers

Getting All Controllers and Actions names in C#

Is it possible to list the names of all controllers and their actions programmatically? I want to implement database driven security for each controller and action. As a developer, I know all controllers and actions and can add them to a database…
sagheer
  • 1,195
  • 1
  • 12
  • 19
29
votes
4 answers

How to achieve a dynamic controller and action method in ASP.NET MVC?

In Asp.net MVC the url structure goes like http://example.com/{controller}/{action}/{id} For each "controller", say http://example.com/blog, there is a BlogController. But my {controller} portion of the url is not decided pre-hand, but it is…
Ray
  • 12,101
  • 27
  • 95
  • 137
23
votes
4 answers

Keeping a controller thin (too many action methods)

I'm working on my first real ASP.NET MVC project and I've noticed that the controller I've been working in is getting rather large. This seemingly goes against the best practice of keeping your controllers thin. I've done a good job keeping the…
Mayo
  • 10,544
  • 6
  • 45
  • 90
18
votes
3 answers

Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL

...guess I'm the first to ask about this one? Say you have the following routes, each declared on a different controller: [HttpGet, Route("sign-up/register", Order = 1)] [HttpGet, Route("sign-up/{ticket}", Order = 2)] ... you could do this in MVC…
13
votes
4 answers

Setting an alternate controller folder location in ASP.NET MVC

We can an MVC app that uses the default folder conventions for the HTML views, but we'd like to set up alternate "Services" folder with controllers used only for web services returning xml or json. So the route "/Services/Tasks/List" would be routed…
12
votes
2 answers

How to get the database context in a controller

I am trying all day to figure out to get the ApplicationDbContext in the ManageController.cs of a default MVC 6 project. I went online and Googled a lot but no one seems to have the same problem as I have with it. It is probably simple but I can't…
StuiterSlurf
  • 2,464
  • 4
  • 34
  • 55
11
votes
2 answers

MVC [HttpGet] controller annotation optional?

If I have 2 controller actions: [HttpGet] public ActionResult Login() { //... return View(); } and [HttpPost] public ActionResult Login(FormCollection values) { //... return…
jtheis
  • 916
  • 3
  • 12
  • 28
6
votes
5 answers

allow hyphens in URLs for asp.net mvc 2 controller names

[ActionName("about-us")] public ActionResult EditDetails(int id) { // your code } The above works for actions but I would like to be able to do the same (or similar) for controllers, ie have a hyphen in the URL name too. Is there any easy way…
6
votes
3 answers

keeping asp.net mvc controller size down

I have a Controller. "OrderController". Currently it's 1800 lines. I like to reduce the size. I'm using static helper methods which is fine but i'm using ninject to call my repositories so don't have access to the repositories in the static methods…
5
votes
1 answer

ASP.NET MVC C# Get controller and action name in class

I'm pretty much new to StackOverflow so please forgive any signs of my ignorance. :) I have a somewhat minor issue with an MVC application in Visual Studio 2010 (Controllers written in C#). I want to create a method which generates an application…
Maciej Ogonowski
  • 71
  • 1
  • 4
  • 8
5
votes
5 answers

Routing not working when sending a DELETE request to an HttpDelete action

I have a ProductsController with only one View - Index.cshtml. The following 3 action methods are inside of this controller: //http://localhost:55555/products [HttpGet] public IActionResult…
5
votes
4 answers

Should controller lifestyle always be transient in Windsor configuration for ASP.NET MVC?

I ran into a problem where I had an Html.DropDownList in my view that would postback the selected value the first time I submitted the form, but each subsequent postback would only post data from the initial postback. So I added…
4
votes
4 answers

Controller post [FromBody] Null issue when when migrating from .netcore 2.2 to 3.0

I had a completely functioning program at version 2.2 when migrating to version 3.0 and replacing public void ConfigureServices(IServiceCollection services) { ... services.AddMvc(); } With services.AddControllers(); And replacing…
ATT
  • 921
  • 3
  • 13
  • 30
4
votes
0 answers

ASP.NET Core Nested / Tiered Controllers

Hi there fellow Overflowing Stackers! Looking for your help in regards to having tiered or nested controllers in asp.net core So far from what I can see, the default boilerplate code, and its default route {controller=Home}/{action=Index}/{id?} only…
1
2 3
12 13