1
votes

I am new to Umbraco and MVC but not to Webforms. I have a partial view that works fine in an Umbraco template, but I would also like it to be available in the content rich text editor, not just in the templates.

The template calls the partial view like:

@Html.Partial("ContactForm", new Mynamespace.UmbracoCms.ContactFormModel())

Under Partial View Macro Files on the Developer tab in the Umbraco back office, I have added the .cshtml file for the partial view.

@inherits Umbraco.Web.Mvc.UmbracoViewPage<Mynamespace.UmbracoCms.ContactFormModel>
@{
    Layout = null;
}

<h3>Contact Form</h3>
@using (Html.BeginUmbracoForm("SendEmail", "ContactFormSurface"))
{
    <div class="formRow">
        @Html.LabelFor(x => Model.Name)
        @Html.EditorFor(x => Model.Name)
        @Html.ValidationMessageFor(x => Model.Name)
        </div>

    <div class="formRow">
        @Html.LabelFor(x => Model.Email)
        @Html.EditorFor(x => Model.Email)
        @Html.ValidationMessageFor(x => Model.Email)
        </div>

    <div class="formRow">
        @Html.LabelFor(x => Model.Comment)
        @Html.EditorFor(x => Model.Comment)
        @Html.ValidationMessageFor(x => Model.Comment)
        </div>


<div class="buttonRow">
    <input type="submit" name="Submit"/>
    </div>
}

I am obviously missing something, yet I cannot find any documentation or tutorials to accomplish what I am looking for.

Thanks for any help you can provide!

1
What is your question? How to make the macro available in rich text editors? - Electric Sheep

1 Answers

1
votes

It sounds like all you need to do is add your macro to the content.

In the Developer section of the Umbraco Admin backend click right on the Partial View Macro Files folder and select create. Leave the Create Macro checkbox ticked and enter a name for your macro. In the .cshtml file created, paste in your call to the partial view and save that.

Then the bit it sounds like you missed is in the content rich text editor, place your cursor where you want the macro and select the Insert Macro from the top bar, where you save and publish and pick styles etc. and select the macro you have just created.

One difference between my version of forms and yours is instead of @Html.Partial() I use @Html.Action().