Copied to clipboard

Flag this post as spam?

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


  • Dee Finken 3 posts 53 karma points
    Jul 09, 2014 @ 16:22
    Dee Finken
    0

    Cannot render surface controller in rte

    Hello,

    I am currently working through the Using Surface Controllers in the RTE video but cannot get the surface controller to render in the rte.  When I click the insert macro button and select the Contact Form macro, I get the error:  Error loading Partial View script (file: ~/Views/MacroPartials/ContactForm.cshtml).

    I changed the value of the <MacroErrors> tag to "throw" in the umbracoSettings.config.  Now I get a different error: Failed to retrieve macro result for macro with alias ContactForm.  Value cannot be null.  Parameter name: content.

    When I created my partial view macro file, I checked the 'Create macro' checkbox so that it would automatically create the macro.

    I have also verified that my Contact Form macro has the "Use in rich text editor" check box checked, and the "Render in rich text editor" checkbox checked.

    I have verified that my partial view ContactForm.cshtml is in the ~/Views/Partials folder and my partial view macro file ContactForm.cshtml is in the ~/Views/MacroPartials folder.

    I am using Umbraco 7.1.4.  Here are some of my code snippits:

    Partial View:  ContactForm.cshtml

    @model MyFirstSurfaceController.Models.ContactFormViewModel

    @if(TempData["success"] == null)

    {

    using(Html.BeginUmbracoForm<MyFirstSurfaceController.Controllers.ContactFormSurfaceController>("HandleFormSubmit") ) {

    <div>

            @Html.TextBoxFor(m => m.Name, new { placeholder = "Name" })

            @Html.ValidationMessageFor(m => m.Name)

            @Html.TextBoxFor(m => m.Email, new { placeholder = "Email address" })

            @Html.ValidationMessageFor(m => m.Email)

    </div>

    <div>

            @Html.TextAreaFor(m => m.Message, new { placeholder = "Your Message" })

            @Html.ValidationMessageFor(m => m.Message)

    </div>

    <div>

    <button id="comment_submit" type="submit">Send</button>

    </div>

    }

    }

    else

    {

        <a>We'll be in touch soon.</a>

    }

    Partial View Macro File:  ContactForm.cshtml

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @Html.Action("Index", "ContactFormSurface")

    ContactFormViewModel.cs

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.ComponentModel.DataAnnotations;

     

    namespace MyFirstSurfaceController.Models

    {

        public class ContactFormViewModel

        {

            [Required]

            public string Name { get; set; }

            [Required]

            [EmailAddress]

            public string Email { get; set; }

            [Required]

            public string Message { get; set; }

        }

    }

    ContactFormSurfaceController.cs

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.Mvc;

    using Umbraco.Web.Mvc;

    using MyFirstSurfaceController.Models;

    using System.Net.Mail;

     

    namespace MyFirstSurfaceController.Controllers

    {

        public class ContactFormSurfaceController : SurfaceController

        {

            public ActionResult Index()

            {

                return PartialView("ContactForm", new ContactFormViewModel());

            }

            [HttpPost]

            public ActionResult HandleFormSubmit(ContactFormViewModel model)

            {

                if (!ModelState.IsValid)

                    return CurrentUmbracoPage();

                //send email

                MailMessage message = new MailMessage();

                message.To.Add("[email protected]");

                message.Subject = "New Contact request";

                message.From = new MailAddress(model.Email, model.Name);

                message.Body = model.Message;

                SmtpClient smtp = new SmtpClient();

                //smtp.Send(message);

                TempData["success"] = true;

                return RedirectToCurrentUmbracoPage();

            }

        }

    }

    Can anyone tell me what I am doing wrong?
    Thank you,
    dfinken
  • Dee Finken 3 posts 53 karma points
    Jul 09, 2014 @ 18:16
    Dee Finken
    100

    I discovered that my content structure was messed up.  After I fixed that, I was able to add a surface controller into the RTE.

    Thank you,

    Dee

  • AmandaEly 123 posts 379 karma points
    Sep 08, 2014 @ 16:45
    AmandaEly
    0

    I have exactly this problem. How did you fix your content?

  • Dee Finken 3 posts 53 karma points
    Sep 08, 2014 @ 17:25
    Dee Finken
    0

    AmandaEly,

    I am a newbe to Umbraco, and my problem was that my content was not structured correctly in the backoffice.  Once I added Home to my content, then added the other content under it, the Surface Controller would render in my rte.

     

    Hope this helps.

     

    Dee

  • AmandaEly 123 posts 379 karma points
    Sep 09, 2014 @ 09:34
    AmandaEly
    0

    Dear Dee,

    Well I do have two home pages (multilingual). Thanks for your help. Don't think that is it though.

     

    Amanda

  • AmandaEly 123 posts 379 karma points
    Sep 09, 2014 @ 17:56
    AmandaEly
    0

    Hi Everyone,

    I have been folowwing Carlos Martinez excellent introduction to Umbraco 7. In this instance, specifically the part about Contact forms (Using Surface Controller). The line: 

    var home = currentNode.AncestorsOrSelf(0).First();

    causes the error loading MacroPartial bug. Annoying for a line which is only added for illustration in case I should need to refer to the home node. Having commented this out, I then get a perfectly rendered contact form.

    Amanda

Please Sign in or register to post replies

Write your reply to:

Draft