public class MetaTagsController : SurfaceController
{
public MetaTagsController()
{
}
[ChildActionOnly]
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.
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.
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:
This will render a partial:
This is the controller:
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.
Based on other questions/answers I've seen, and other forum posts, I can't see what I'm doing wrong?
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.
See https://our.umbraco.com/documentation/reference/routing/surface-controllers
Thanks Andrew, the namespace got it!
is working on a reply...