My MVC3 app is adding "/Controllers/" folder to all my links - asp.net-mvc-3

I've inherited an MVC3 .NET web app, which had all the controllers for the site in a separate project to the main web app. Not sure why this was the case. As it's a small app, I decided (for "neatness") to move the controller code back into the main web project, under the usual "Controllers" folder.
"Controllers" project folders:
Admin
Members
Config
Moved above code into main Web project under "Controllers" folder, ie:
Controllers
Admin
Members
Config
The problem now is, all the links generated by the code include "/Controllers/" in the path, assumedly because the controller code is now in a "Controllers" project folder. Is this a simple MVC issue to fix? Or would it likely be a flaw in code itself, in that it relies on where the code files run from to generate links?

Related

Default class folder in Xamarin.Forms

What is the default class folder in Xamarin.Forms?
In web development solution there is App_Code folder, where should I use in Xamarin.Forms ?
You can organize your code however you like. You can place everything in the root folder, or create separate (even nested) folders. Xamarin Forms does not require any special folder structure.
I tend to use a structure like this, but this is solely my preference:
Root
- Model
- View
- ViewModel
- Service
- Data

How to prevent a new controller from creating a new folder for its views in the Views folder?

I'm writing an ASP.NET MVC 5 application, where folders are organized by feature (ViewModels, Controllers, and Views are grouped together). I was able to override all default folder paths and manage all routing successfully. However, every time I create a new controller, Visual Studio creates a new Views folder and a child folder with controller name, which is a little bit annoying but that's fine.
Now, when I create another controller, I'm getting this error, because Visual Studio created the Views folder again, which is hidden now (excluded from the project). To fix this, I have to include the Views folder in the project and delete it after I create the controller.
Does anybody know any way to prevent this?
Error
There was an error running the selected code generator: 'A file or
folder with the name 'Views' already exists on disk at this location.
Please choose another name.
If this file or folder does not appear in the Solution Explorer, then
it is not currently part of your project. To view files which exist on
disk, but are not in the project, select Show All Files from the
Project menu.
Instead of using visual studio's Add -> Controller which generates the undesired view folder, create your controller using Add -> Class. Name the class conventionally with a Controller suffix and subclass Controller like this MyController : Controller.

How to use ASP.NET MVC view precompilation with App_Code helpers?

I am trying to enable view compilation to have my ASP.NET MVC3 web site load faster. My web site is hosted on AppHarbor.
However, my views make use of MVC3 view helpers, defined in the App_Code folder.
When I try to load my web-site, I get:
"The directory '/App_Code/' is not allowed because the application is precompiled."
How can I stop the App_Code folder being deployed to the web-server, but still have the App_Code helpers pre-compiled?
I've tried changing the helpers to Content=None, but this leads to an AppHarbor build error because the helper files cannot be found during pre-compilation.
Old question, but I just got that problem, and the following procedure has worked for me:
Go to https://appharbor.com/your-application.
Click on Settings.
Click on Build | DISABLE PRECOMPILATION.
Force appharbor to do a rebuild/redeploy (by pushing a new commit to the repository).
I have just deleted my shared helpers and deleted the App_Code folder because of this problem. I have changed my project to use partial views instead .
According to this answer helpers must be in the App_Code folder but this won't work using AppHarbor.
I would say , don't use App_Code folder in web application. Please find more details ****here****

ASP.NET MVC3 project does not always publish all views/content

This is crazy, but I can't seem to get all my views/content/scripts published when I publish the site. This seems to happen, I believe, when the view or content is not directly referenced by my project, but used by another assembly in my project. So I might have:
ExternalAssembly.dll referenced (it gets published)
I'll need ExternalLogin.cshtml in my main project, under my views folder
ExternalLogin.cshtml doesn't get published
Right now I have a script that copies everything in the Views folder and dumps it to where I want it deployed, but VS should do this for me. What am I doing wrong?
When you click on one if these files what is the build action for it on the properties? Content....or? Set to content.
So your views files are in another project or folder outside your current project? Normally the files have to exist in the web site project, in it's views folder, not externally, and the build action should be set to Content and not to copy to the output folder. But there are some workarounds:
Duplicate them in to your site views folder and make sure they are marked content (as stated in another answer). One thing to note though is that you can add them as "Linked Files" in visual studio which actually allows them to exist in two places in the hierarchy without having to exist in two places on disk: http://support.microsoft.com/kb/306234
If you have control over the external library, you can compile them in as embedded resources or use Razor Generator or something similar and use a custom view engine to return them: How can I make ASP.NET MVC 3 use views (aspx, ascx) files from an external assembly in my website?
Manually put the copies in the .csproj build XML using the Copy task: http://msdn.microsoft.com/en-us/library/3e54c37h.aspx (Note that this will make it work in visual studio doing essentially what you are doing now, as it will then be part of the Visual Studio build if you add it to the AfterBuild target or something)

Mobile and desktop web app with codeigniter

I want to build two versions of my project for mobile and desktop.
Am working codeigniter 2.0.2, am looking for a way for the mobile and desktop versions of the project to share the same model, controllers, libraries, and helpers.
Also i have set up a sub-domain,m.xyz.com to point to folder called "m" on public_html folder,
i want the the mobile to be in the "m" folder and share resources with the desktop app residing in root so i dont create duplicate models, controllers etc.
CodeIgniter allows you to specify the folder that you are loading your views from. Since you want to reuse all of your application code, simply set up CodeIgniter so that it is loading mobile optimized views rather than the default (desktop) views.
Copy the root index.php file into the /m/ folder that you created.
Update the $system_path and $application_folder variables in /m/index.php with the correct paths.
Update the $view_folder variable in /m/index.php with the path to your view folder containing your mobile optimized views.
You mobile site will now mirror your desktop site - it will just be pulling in different views.
Note that the structure of your mobile views folder will need to mirror the structure of your default views folder.
EDIT: The $view_folder option will not be available until version 2.1. Here is the code if you wish to make the change yourself:
https://github.com/EllisLab/CodeIgniter/commit/8eef9c77512d4fad5357d3cbda83b89f844d7d16

Resources