Copied to clipboard

Flag this post as spam?

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

  • Jake Platford 7 posts 108 karma points
    15 days ago
    Jake Platford

    Html.RenderAction returning an error

    I am having issues with using Html.RenderAction, currently I have the following in the head of the site on the master page:

        Html.RenderAction("RenderMetaTags", "MetaTags");

    This will render a partial:

    @model MetaTagsModel 
    @* do stuff *@

    This is the controller:

    public class MetaTagsController : SurfaceController
        public MetaTagsController()
        public ActionResult RenderMetaTags()
            IPublishedContent currentNode = CurrentPage;
            string urlSegment = Request.Url.Scheme + "://" + Request.Url.Host;
            MetaTagsModel metaTagsModel = new MetaTagsModel()
                MetaTitle = currentNode.MetaTitle(),
                MetaDescription = currentNode.MetaDescription(),
                MetaImageUrl = currentNode.MetaImage(),
                IsLiveSite = bool.Parse(ConfigurationManager.AppSettings["IsLiveSite"]),
                CanonicalUrl = urlSegment + currentNode.Url()
            return base.PartialView("~/Views/Partials/Custom/Template/MetaTags.cshtml", new MetaTagsModel());

    I'm doing it this way because there'll be different logic for how meta information is pulled from the CMS and then rendered on the page. I wanted all of that logic to be in the controller and not the view (I can just use RenderPartial if it was all in the view).

    I am getting the following error, which is produced by the Html.RenderAction line. Debugging never hits the controller.

    [NullReferenceException: Object reference not set to an instance of an object.]
       Umbraco.Web.Mvc.ContainerControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +83
       Umbraco.Web.Mvc.UmbracoControllerFactory.CreateController(RequestContext requestContext, String controllerName) +93
       Umbraco.Web.Mvc.RenderControllerFactory.CreateController(RequestContext requestContext, String controllerName) +14
       Umbraco.Web.Mvc.MasterControllerFactory.CreateController(RequestContext requestContext, String controllerName) +53
       System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +187
       System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
       System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
       System.Web.Mvc.<>c__DisplayClass2_0.<BeginProcessRequest>b__0() +31
       System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +27
       System.Web.Mvc.ServerExecuteHttpHandlerAsyncWrapper.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +98
       System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2013
       System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +77
       System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +25
       System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +20
       System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +468
       System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName) +35

    Based on other questions/answers I've seen, and other forum posts, I can't see what I'm doing wrong?

  • Andrew Z 2 posts 92 karma points
    14 days ago
    Andrew Z

    It probably is just not part of your code sample posted here, but make sure your Surface Controller is part of a namespace, Umbraco won't load it up otherwise.


  • Jake Platford 7 posts 108 karma points
    1 week ago
    Jake Platford

    Thanks Andrew, the namespace got it!

Please Sign in or register to post replies

Write your reply to: