0
votes

Umbraco ver. 4.7

My project is running along side asp.net MVC 4. I have a Umbraco page, which has a Rich Text editor property on the document type, that will retain a body of text with HTML.

Is there a way to use a System.Net.WebClient client, and request the Umbraco page from within my MVC project and have it return the content of that page's document property to the MVC controller's WebClient request?

Bonus Question:

Is there a way to setup an Umbraco macro in the template that will parse the querystring params and have place holders in the Umbraco template that the macro will replace the placeholders with the parsed out querystring params before the content is returned to the request (explained up above)?

2
maybe I'm not understanding the question correctly, but wouldn't it be simpler to include the Umbraco DLLs in your MVC project and access the content via the Umbraco API? - Jonathan
Well, I am not well versed in Umbraco and I didn't setup the MVC/Umbraco project - some of the umbraco dll's are in included and some of Umbraco is not. Maybe an example of what you were thinking? Sometimes it's hard to know your options, when you don't know what is possible. - pghtech

2 Answers

1
votes

Add a reference to umbraco.dll and umbraco.MacroEngines.dll in your MVC4 project.

You should then be able to do (within your controller or view):

dynamic d = new DynamicNode(nodeId);
return d.AliasOfRichTextProperty
1
votes

Have you used the /Base extension in Umbraco? I believe this may help you out, because I had similar requirements and found /Base extremely powerful. In my document type I actually used a multi-line textbox as input for the html (or in my case Razor script). In my /Base class I created a method that finds the correct node, takes the raw script from the textbox, renders the script into a raw html string, and returns the string wrapped in a tag .

public static string GetRazor()
    {
        var doc = new DynamicNode(nodeId);

        string razorScript = doc.GetPropertyValue("{propertyAlias}");
        string razorString = RenderRazor.RenderRazorScriptString(razorScript, nodeId);            

        return razorString;
    }

Another way is to create a macro within Umbraco which your template can call, something like:

   @using umbraco.MacroEngines
   @{
       dynamic node = @Model;
       string htmlString = node.GetPropertyValue("{propertyAlias}");
       @Html.Raw(htmlString)
    }

Then inside your template, you just need to inject the macro:

<umbraco:Macro Alias="{RazorAlias}" runat="server"></umbraco:Macro>

Whatever html in your textbox will be rendered by the razor engine!

-Dan