Umbraco: creating user control - umbraco

I'm new to Umbraco. Currently is using v7.1.4.
I know that MVC partial views can be created under Settings > Partial Views.
If I have switch the rendering engine from MVC to webforms, where should I create .Net user control?

Just to add to CMayers answer, i generally prefer to create a separate project called usercontrols (just for the sake of knowing what it is) and then using xcopy in the build event copy the dll to the bin folder of the umbraco installation. Likewise the ascx pages are copied into the UserControls folder of the umbraco installation.
Then from the umbraco backend in the developer section, you can create the macro and associate the relevant ascx page to it.

All your .NET Usercontrols should be created in the 'UserControls' folder that comes with the default Umbraco installation.
If you don't copy them to here, then you wont be able to access your user controls from the Macro section of the CMS "Choose a file to render".

Related

In MVC what extension should the view file names have?

I have been given a sample MVC project that contains views with extension .aspx
however when I create a new MVC project using the VS2013 ASP.Net wizard the views have extension .cshtml
Are there 2 kinds of MVC project?
Views in MVC refer to either .cshtml files in C# or .vbhtml files in Visual Basic.
.aspx files are webform files and are not views-- this was the initial approach ASP.NET took to make webform development more similar to desktop application development. These pages are generally included in the route list as actual files, whereas MVC uses controller routes that aren't based on existing files (i.e., the url path doesn't match the file and directory structure like traditional html does), which ultimately serve the views. .aspx files can also have code-behind files to separate the html/aspx markup from the .NET code; those files will have either a .aspx.cs or .aspx.vb extension on them. In an MVC app, these files are also likely to have designer files.
One set of files for an aspx file named MyPage may have the following files:
MyPage.aspx
MyPage.aspx.cs or MyPage.aspx.vb
MyPage.aspx.designer.cs or MyPage.aspx.designer.vb
The files in #3 may be hidden until you select 'show all files' in the project, or may not exist at all in a traditional 'web site' project type. I think you have to upgrade to a 'web application project (Wap)' project type before you can integrate MVC, though I may be wrong. All WAP projects should have these .aspx.designer.xx files.
In MVC what extension should the view file names have?
.cshtml unless you have a reason not to use the Razor view engine with C#.
Are there 2 kinds of MVC project?
The relevant answer is that there are many more than 2 different view engines. Razor was introduce in 2010. The Razor view engine is what comes out of the box in the Visual Studio MVC templates. See ASP.NET MVC View Engine Comparison for more info on more obscure view engines that work with ASP.NET MVC.

MVC empty WebSite project based on aspx pages

In Visual Studio we have a two ways that create the web projects.
I create the "WebSite" project, empty-project (like: File -> New -> WebSite... and so on).
After that, when the WebSite created I want to make it to MVC WebSite with ASPX, and not Razor pages.
[I decide create the MVC WebSite not Project Site, with this way, because the Visual Studio doesn't provide us WebSite with MVC template based aspx pages].
After creating some pages I want to create and integrate any Razor page.
Describe for question:
IF I attempt use in the Razor view page - " #model MyWebSite " it does not discovering, and I can't use with the ViewBag property later
Question:
What Can I do ?
What NuGet packeg I need install or what dll recourse I need adding to Bin folder of project.
Yes, you can use Razor with an existing ASP.NET WebSite. Simply open your website using the WebMatrix tool and start adding CSHTML files. One caveat is that if your website is using WebForms controls the WebMatrix tool will not provide any help working with them in existing aspx pages. Additionally, Razor does not support WebForms so you will not be able to add something like to a CSHTML file.

Add controller/view on other folders

Initial sidenote: I'm working on a hybrid WebForms+MVC application that started as a WebForms application hence I've added project GUIDs that converted it to MVC. This means that I'm getting context menus directly on Controllers and Views folder in application root. That works.
I was wondering whether it's possible to convince Visual Studio (and Asp.net MVC tooling) to add Add controller... and Add View... context menu items to other folders not just those default ones that are on the project root?
The reason is that I'm working on an Asp.net WebForms application that is now a hybrid with MVC. And since it already has quite a few folders in root I would rather separate the new MVC part and contain it altogether within mvc folder, so all MVC related files would be inside that particular folder.
But right clicking on mvc\Controllers doesn't give me the wizard, nor does the mvc\Views... Also navigation from controller code to views isn't working...
Is there any way to customize this in Visual Studio? Do Asp.net MVC tools for VS have some sort of configuration file where this can be configured? Or in registry maybe?
If you wish to separate the MVC stuff from the rest of the application you might want to put it in a separate Area.
You'd have the context menu and separation from the existing mess.

How to seperate MVC project to several smaller MVC projects

I have an MVC 3 app that has some core functionality (most important is autorisation) but mainly serves as a portal to different areas or modules. I want to organize thit to different modules that with minor changes also can be deployed as their own website.
The project consists of a Forum, Blog engine, Messaging between users + 4-5 upcoming modules.
I looked at ScottGu's blog about MVC 2 and found something that seemed perfect:
Depending og what the customer need I want to only give them the exact modules they can use. It is also easier from a maintainence view to be able to work and update referencd assemblies in each project and just do a full update for the customers that have that spesific module on their server.
But in MVC 3 there is no apparent way to use Areas this way, do you know how?
Status
I will try to add MVCContrib Portable areas to my existing solution and convert my areas ower and will post back the results. If it works I will mark it as the accepted solution.
MVCContrib has portable areas.
http://mvccontrib.codeplex.com/wikipage?title=Creating%20a%20Portable%20Area&referringTitle=Documentation
This is possible in MVC3:
From:
http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects
Right click on the shell project and "Add Area...". Type in the area name. This will create an Areas folder with your area in it. (This is not 100% needed but you do need the "Areas" folder and you can steal the XXXXAreaRegistration class for your application.)
Create a new MVC3 empty project in your solution to match your area. Move the XXXXAreaRegistration.cs file from the shell mvc project to the new project and adjust the namespace as applicable. (Or you can manually create an area registration class, it's a pretty simple class. Just use the Add area template generated one as an example.)
Edit the routes in the AreaRegistration folder as needed.
Delete the folder under the areas folder that the template wizard added.
Modify the web.config of the new project and take out the connection strings and the authentication, membership, profile, rolemanger sections. You will not need to deploy this web.config but the razor intellisense doesn't work without it during dev time.
Delete the global.asax file from the area's project or you will get extra default routes.
Create a virtual directory in the "Areas" folder of the shell project with the name of your area as the alias and point it to your "area" project. You will need to use IIS or IIS Express for this. I use IIS. For IIS Express you can use the appcmd.exe in the IIS Express folder or you can edit the applciationhost.config file.

Include MVC views and master pages as DLL resources instead of separate files

Does there exist a method when publishing an ASP.NET MVC application to completely remove the .aspx view files (and if possible .master too) by compiling them into the application DLL as resources?
The published application would just be the /bin folder, Global.asax and web.config, a default.aspx if needed, and whatever is in the /Content folder. All the views would be contained in the MyProject.dll file.
To clarify I don't mean where every .aspx is overwritten with a 1 line dummy file referencing the correct resource, but where those files can be eliminated entirely in the published app.
The goal here is to simply change management and all the auditing and layers of people surrounding it - one file gets deployed, that file replaces the existing file, and no messing around with a stack of .aspx files that have to be added/removed/updated (yes, SVN or a similar solution handle that problem instead, but management politics prevent this).
Is this what you are looking for?
It's possible with the web forms view engine but you'll have to extend the path provider yourself.
Here is a question here at SO about the same thing:
Using VirtualPathProvider to load ASP.NET MVC views from DLLs
If you use the Spark view engine, it already has additional path providers built in.
The documentation can be found here:
Adding a view folder to config
It allows you to locate your views inside a DLL as an embedded resource, somewhere else on the file system, using the default virtual directories, or plug in your own custom provider.

Resources