Skip to main content

ASP.MVC in Umbraco 6

Umbraco 6 brings new lots of improvements for developers, new datalayer, new API’s and complete support for Asp.net MVC 4. This means developers will have greater control, simpler code and higher productivity when developing with Umbraco.

As the umbraco blog says, in Umbraco 6 we have:

  • MVC support, 
  • Native Razor support
  • Strongly typed views  
  • Building custom controllers
  • Whole new shiny API
  • Customizing routes.
  • and many more..
Download the latest version 6.0.0. from http://umbraco.codeplex.com/releases .

Create a blank MVC4 Application, and add the downloaded files to the newly created website. so that it will make the debugging easier.

OR run NuGet Package Manager Command : PM> Install-Package UmbracoCms

Now we can enable the mvc in ~/config/umbracoSettings.config 

<defaultRenderingEngine>Mvc</defaultRenderingEngine> by default it will be web forms change it to Mvc.

Add another blank MVC4 project to the existing project, and add reference to umbraco.dll, businesslogic.dll, and interface.dll. these dlls can be found in umbraco bin folder, and now are ready to create controller, or business logic that we will be using in our Umbraco project.

Create the controller that inherits from SufraceController, and add the logic what you would like to see in your page.
e.g: 
public class CommentsController : Umbraco.Web.Mvc.SurfaceController
{
        [HttpGet]
        public ActionResult Comments()
        {
            List<CommentViewModel> model = LoadComments();
            return View(model);
        }
}

Add a partial view to render this model, Build the MVC project, and copy the dll, and Views to Umbraco Bin and Views folder.

We are set now, add the controller, as action in the Umbraco Template. You could see the created controller and view getting fired on the Umbraco Page.

More information can be seen at http://our.umbraco.org/documentation/reference/mvc/

Comments

Popular posts from this blog

Why not to have a static const in c#

This is just a thought, that I was thinking why can't we have a constant with static in C#, and the answer is 'NO'; That we cannot have a static constant; e.g: I created a class as below: public class Constants1 { public const string Const1 = "Hello"; public const string Const2 = "World"; public static string Static1 = "Hello Static"; } When we compile the program into IL, the C# compiler does a magic in IL, that the constants converts into static literals, of course it has to, that's why we are able to access the constants as Constants1.Const1

Beyond Solo Assistants: Google's Vision for AI Teamwork (Agent-to-Agent Collaboration)

We talk a lot about AI assistants like Google Assistant or chatbots answering our questions. They're pretty smart on their own, right? But imagine if they could team up, combine their unique skills, and tackle really complex problems together, just like a human team does. That's the core idea behind a super exciting area Google and others in the AI world are exploring: Agent-to-Agent (A2A) communication and collaboration. Think of it less as a single product called "Agent2Agent" and more as the science and engineering of building AI teams. Ready to explore why this is such a big deal? Let's break it down! First Off: What Even is an AI Agent? Think of an AI agent as a specialized digital helper. It's a piece of software designed to: Perceive: Understand its environment (text, images, data, user requests). Reason: Figure out the best course of action based on its goals and knowledge. Act: Perform tasks (answer questions, writ...

Create Document Dynamically (Umbraco)

You can create document and publish the content during run time, Below code snippets helps you to do it. public class UmbracoUtils { /// <summary> /// Create and publish the document programatically /// </summary> /// <param name="nodeName"></param> /// <param name="properties"></param> /// <param name="documentType"></param> /// <param name="parentId"></param> /// <returns>node id</returns> public static int CreateDocument(string nodeName, Dictionary<string, string> properties, int documentType, int parentId, List<string> roles = null) { DocumentType dt = new DocumentType(documentType); umbraco.BusinessLogic.User u = new umbraco.BusinessLogic.User(0); // Create the document Document d = Document.MakeNew(nodeName, dt, u, parentId); // Add values...