I want to be able to create custom macros for editors outside of Umbraco. I was able to do this previously with WebForms.
I found a way to do this, and it works , but I am wondering if the following is a good idea, or if there is a better way of doing this.
Create an MVC project
Remove reference to System.Web.Mvc.dll
Add references to [Umbraco Project Folder]\bin
\interfaces.dll
\System.Web.Mvc.dll
\umbraco.dll
Create controllers
reference the Area name for the Plugins folder
inherit from Umbraco.Web.Mvc.SurfaceController
return partial views (these need to be saved in Views/Shared)
Sample MVC Controller using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
namespace Test_MVC_Macros.Controllers
{
[PluginController("MyMacroControls")]
public class SampleController : Umbraco.Web.Mvc.SurfaceController
{
//
// GET: /Sample/
public ActionResult Index()
{
return PartialView("SampleView");
}
}
}
put Views folder in [livesite]/App_Pluggins/MyMacroControls
Don't copy the Views web.config file over to the livesite (this gave me some trouble and the live site seemed to correct it and place it's own web.config file there once I removed the copied version)
To use this as a macro in a page:
Create a new Partial View Macro
Add the following line:
@Html.Action("Index", "Sample", new { area = "MyMacroControls" })
So it would look like this:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@Html.Action("Index","Sample", new { area = "MyMacroControls" })
To postback using Html.BeginUmbracoForm I found I had to add the following to the web.config, place a copy of businesslogic.xml (found in the Umbraco project bin folder) in the bin folder of the MVC project, and then rebuild the MVC project:
MVC Custom Macros for editors
I want to be able to create custom macros for editors outside of Umbraco. I was able to do this previously with WebForms.
I found a way to do this, and it works , but I am wondering if the following is a good idea, or if there is a better way of doing this.
Add references to [Umbraco Project Folder]\bin
Create controllers
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Umbraco.Web.Mvc; namespace Test_MVC_Macros.Controllers { [PluginController("MyMacroControls")] public class SampleController : Umbraco.Web.Mvc.SurfaceController { // // GET: /Sample/ public ActionResult Index() { return PartialView("SampleView"); } } }
Add the following to the web.config file
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> </dependentAssembly> </assemblyBinding> </runtime>
Build MVC site as normal
To use this as a macro in a page:
So it would look like this:
@inherits Umbraco.Web.Macros.PartialViewMacroPage @Html.Action("Index","Sample", new { area = "MyMacroControls" })
To postback using Html.BeginUmbracoForm I found I had to add the following to the web.config, place a copy of businesslogic.xml (found in the Umbraco project bin folder) in the bin folder of the MVC project, and then rebuild the MVC project:
<configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> <add namespace="Umbraco.Web" /> <add namespace="Umbraco.Core" /> <add namespace="Umbraco.Core.Models" /> <add namespace="Umbraco.Web.Mvc" /> <add namespace="umbraco" /> <add namespace="Examine" /> <add namespace="Umbraco.Web.PublishedContentModels" /> <add namespace="NES_Intranet_Controls_MVC" /> </namespaces> </pages> </system.web.webPages.razor>
is working on a reply...