Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ben 112 posts 398 karma points
    May 23, 2017 @ 15:31
    Ben
    0

    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.

    1. Create an MVC project
    2. Remove reference to System.Web.Mvc.dll
    3. Add references to [Umbraco Project Folder]\bin

      • \interfaces.dll
      • \System.Web.Mvc.dll
      • \umbraco.dll
    4. 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"); } } }
    5. 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>

    6. Build MVC site as normal

    7. Put project DLL file in live Umbraco bin folder
    8. 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:

    1. Create a new Partial View Macro
    2. 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" })

  • Ben 112 posts 398 karma points
    May 25, 2017 @ 13:10
    Ben
    0

    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>

Please Sign in or register to post replies

Write your reply to:

Draft