Getting 'Multiple Controllers Found' Error - asp.net-mvc

I am getting this runtime error from a new project.
I actually don't have any duplicate controller names. They all reside in my Controller folder and have unique names. I am not sure why I'm getting this.
I also did follow the suggestion to add a namespaces parameter even if they were all located in one folder.
Multiple types were found that match the controller named 'Channel'.
This can happen if the route that services this request
('{controller}/{action}/{id}') does not specify namespaces to search
for a controller that matches the request.
If this is the case,
register this route by calling an overload of the 'MapRoute' method
that takes a 'namespaces' parameter.
The request for 'Channel' has
found the following matching controllers:
MyProject.Controllers.ChannelController
MyProject.Controllers.ChannelController

It turns out I had another DLL in the same folder. I renamed my project, and the older DLL was there with exactly the same controllers.

Related

Cannot find my View

All my Views are defined in a folder called "site_admin". But when I browse like this http://localhost:1234/site_admin/home/index. It gives me the following error
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /site_admin/home/index
It looks like its having problem finding the location of my View. All my views should be inside the "site_admin" folder and should be accessible from there.
Any help would be greatly appreciated.
Here is how routing works in MVC. Default routing means you have a controller, like UserController and in that file there is a method, say NewUser(...). Then you also need a view folder named User and inside that a NewUser.cshtml file. Now, if you to to mysite.com/User/NewUser that will first hit the User controller and look for the NewUser method. Once that code is run it will look for the NewUser.cshtml file in the Views/User folder.
There are several way of overriding this default routing (routeconfig.cs, route attributes, etc) but that is the basics of how it all ties together.

grails #Resource Annotation before Domain class

When I create a RESTful API in Grails, I add #Resource(uri='env',formats=['multipart/form-data'] before the domain class. And then use grails generate-all domain_name to generate the controller and view.
However, in Eclipse there is an Java problem like
The project was not built due to "RequestEnvironmentController$_on_closure51 [in [Working copy] RequestEnvironment.groovy [in test.environment.manager [in grails-app/domain [in restful-api-for-tem]]]] does not exist". Fix the problem, then try refreshing this project and building it since it may be inconsistent.
Then I get rid of the annotation and the error disappears and the post method still works. I am confused, is the annotation necessary or not? If it is necessary, how can I remove the Java error?
When you use the #Resource annotation there is no need to create a controller because this will be automatically generated as per documentation
Simply by adding the Resource transformation and specifying a URI,
your domain class will automatically be available as a REST resource
in either XML or JSON formats. The transformation will automatically
register the necessary RESTful URL mapping and create a controller
called BookController.

ZF2 view script path generation

The ZF2 tutorial puts the view scripts into module/Album/view/album/album and it says "stored in our module’s views directory within a directory named after the controller".
The controller is AlbumController so that must be one of the 'album'-s. But where does the other 'album' come from?
I have tried to debug the framework to figure this out, but with all this magic calls and triggered events I got lost completely in a minute.
The default structure is:
view/[module]/[controller]/[action].phtml
As you have an Album Module, and an Album Controller, your views would go into that directory.
if you have an action named indexAction then your view would be called index.phtml

Add a reference to ASP.NET MVC ASPX page

I have some HTML Helpers that I imported from an external project. How do I reference them within the ASPX file?
Currently I get an error similar to the following:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper<LC.TLAdminMVC.DAL.BusinessObjects.CompanySingleViewModel>' does not contain a definition for 'Configurator' and no extension method 'Configurator' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<LC.TLAdminMVC.DAL.BusinessObjects.CompanySingleViewModel>' could be found (are you missing a using directive or an assembly reference?)
To better understand your situation can you answer one question.
Have you placed the helper methods inside the aspx files or are they external?
If they are external:
Make a directory in your solution named: app_code
Create a new file, whatever name (we'll call it 'Content')
When you want to use the helper method just call Content.methodName(params)
If they are internal:
Try checking if they are not nested inside a block.
Hope this helps,

Renaming namespace in ASP.NET MVC Project: compile OK, Running not OK

How to fix ?
Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.
The request for 'Home' has found the following matching controllers:
MyProject1.Controllers.HomeController
MyProject2.Controllers.HomeController
Probably need a little bit more details. For e.g. Did you change the namespace from MyProject1 to MyProject2?
Check your bin folder to see if any of dlls from the old namespace are still around. If that's the case cleaning them up and recompiling should fix the issue.
Make sure you edit the default namespace setting in your web project properties, on the Application tab.
I assume this is in your Views. Be certain the namespaces in your views is correct.

Resources