Where are cshtml files and Controllers in Umbraco with Mvc? - umbraco

I've just installed Umbraco 6.1.6 making sure to have this setting in the \Config\umbracoSettings.config file before starting the install process.
<defaultRenderingEngine>Mvc</defaultRenderingEngine>
The site has installed fine, and runs fine, but the site is still full of .aspx and .ascx files. What gives? Shouldn't it have created .cshtml files for views, layouts and Controllers and stuff?
Or have I misunderstood and that is up to the user to put in?
Cheers,
-- Lee

Some part of umbraco will still use UserControls.
Try making a new documentType, that will create a view that matches that doctype
You can overrule the default Controller by creating a Controller with the same name.
Remember to inhert from.
public class NameOfTheDocTypeController : Umbraco.Web.Mvc.SurfaceController

Related

MVC .NET Core 2.0 - _Layout static files do not load for action methods of a controller

I started a new project in VS 2017 and created a ASP.NET Core 2.0 web application (Model View Controller). Then I've changed the conent of the _Layout.cshtml to the interface I want to use (included #Renderbody etc.) and included all the static content it requires in the wwwroot and save and Ctrl+F5 and the layout shows with all the correct formatting and functionality. No problem so far:
However from this point forward none of the static content files of the _Layout shows in any other view. So for example if I visit any of the following URLS:
http://localhost:52786/home/
http://localhost:52786/home/index
http://localhost:52786/home/about
http://localhost:52786/home/contact
I see this:
Startup.cs already has app.UseStaticFiles() in Configure()
So it sounds like you may have your HTML body content in the wrong place. With ASP.NET MVC &ASP.NET Core MVC, the HTML for each page is served up from the /Views directory (by the Home controller by default), not from the /wwwroot, and it is C# HTML (.cshtml) just like the _Layout.cshtml file. Things like images, static javascript etc. are what's typically located in the /wwwroot directory as these are the parts of your website that are client side instead of server-side.
Try replicating your index, about and contact HTML content as .cshtml files under the /Views/Home directory, replacing whatever's there in the template, except for #{ViewData["Title"] = "Home";} located at the top. The layout template should then serve these as the body content (where #renderbody... is in _Layout.cshtml).
If this still doesn't work I'll need a bit more info about what you've changed from the default template. Hope this helps!
Thank you James for your response. I figured it out and it's actually a noob mistake which I'm posting so that other new developers don't get caught in it.
When you want to reference the content in the wwwroot folder if you reference them without "~/" before the name of the directory it works for the _Layout page which fooled me to think it should work for other parts of the application but you should include "~/" before the folder names explicitly otherwise the static files will be un reachable.

ASP.NET MVC Displaying Static Help Website

I'm trying to add Help to my ASP.NET MVC project.
The "help" website contains static pages about the features in my ASP.NET application.
I have added the content for this website into my ASP.NET MVC project and have added a hyperlink that will open the Help in its own window.
However, when I try to access the content, the application attempts to route to the Help controller.
How do I display the help website within my MVC application?
I am not sure you can do this within the context of an MVC application. I would consider just building an empty controller with an Index action (HelpController -> public ActionResult Index()) and just return the view name (cshtml file), shouldn't be any reason you can't rename your static html file to cshtml even if you aren't using razor (although I am not 100% sure without trying that the extension change is necessary). Also I would argue that if this ever needs more functionality you have the scaffolding in place to make non-static mods. Disabling routing within the context of an MVC solution honestly doesn't make the most logical sense. The only other choice would be if you hosted it in a different IIS site (but I don't think I would recommend that unless you have a huge help library).
Use IgnoreRoute when you configre your routing, for example, create a folder "help" in your app's root. Then load it with all your html help files. Then to ignore that route:
routes.IgnoreRoute("help");
You should then be able to access it by http://myapp.com/help/whatever.html

The Controller folder is empty after installing the RoadKill wiki engine

I have installed Roadkill Wiki engine (2.0.275), but i am facing these problems:-
when i run the project using visual Studio 2012 , i got the following message, on the home page:-
You have no mainpage set
To set a main page, create a page and assign the tag 'homepage' to it.
Also i have noted that the Controller folder is empty, while the View folder do have sub folders. so do i have to create the controller classes manually ?
Thanks
The main page message is from you having no pages created in the Wiki, at least with the "homepage" tag - that's how Roadkill picks out the homepage page.
The structure of the project is slightly, or infact completely different, from the standard MVC template. All C# code including controllers and models can be found in Roadkill.Core. All views, CSS and Javascript (or Typescript) is found in Roadkill.Web.
So to find the controllers and models, have a look in:
Roadkill.Core
- MVC
- Controllers
- Models

How to default your asp.net-mvc site to look for razor views first?

I am converting all of my views over to razor so I have created all new view files but I haven't deleted the aspx file (I just have them excluded from the project). When i go to test my site, it seems to try to look for and load the aspx files. When I delete these files, it works fine and defaults to my razor cshtml files.
My issues, I that i want to keep my aspx files around for a little bit (at least until i know everything is working).
Is there anyway to have an asp.net-mvc site look for razor view files first so i don't need to delete my aspx files to get this to work?
The default order for view engines is Web Forms then Razor. Just change the order.
protected void Application_Start() {
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
ViewEngines.Engines.Add(new WebFormViewEngine());
// remaaining calls here
// ...
}
I ran into the same issue when migrating a site from webforms to mvc. However I encountered the issue that MVC is greedy. My site would default to the mvc views and not the webforms. Ultimately what i did was create a new folder off the root of the webforms and set it as new application starting point. Then upload the mvc site into this folder. Then once i know all is well then i can take the webforms down. I found this to be best option.
Edit: Should've mentioned i tried the ignore routes thing to ignore .aspx pages - did not work for me at all.

Ascx in different folder?

I am working on an web application that uses themes and different master pages. Each master page is at the shared folder with their names; such as Shared\Themes\MyTheme\Site.master
and the views are at \ControllerName\ListUsers.aspx
In the controller; I call the view : return View("ListUsers",ThemeEngine.MasterPage,Model);
So far everything works fine; however when I try to call RenderPartial inside the ListUsers, I am getting usercontrol can't be found error because my user controls are at the master page folder such as \Shared\Themes\MyTheme\SingleUser.ascx
Is there a way to tell the framework to look for the user controls in a different folder than \Shared but \Shared\ThemeNAme etc...
Yep. You can specify the path to the View using the virtual root. There's nothing stopping you from passing in a full path.
return View("~/Shared/Themes/MyTheme/SingleUser.ascx");
How to change default view location scheme in ASP.NET MVC?

Resources