0
votes

Hi I am having a lot of trouble with rendering an umbraco grid.

I have a solution with umbraco 7.6 and MVC. So in my controller I want to try and add the rendered grid to my model, so I can call that model in the view.

In my controller:

public ActionResult BlogItem()
{
    var model = new BlogItemViewModel();
    // GET grid 1
    var aboutGrid = CurrentPage.GetGridHtml("gridLayout");
    //add to model.
    model.GridLayout = new HtmlString(aboutGrid.ToHtmlString());
    return View(model);
}

And in my view I should be able to just call this:

@Model.GridLayout

But I get an exception, which doesn't really tell me much in my controller when trying to call it.

System.Web.HttpCompileException: 'External component has thrown an exception.'

$exception error CS0246: The type or namespace name 'UmbracoViewPage' could not be found (are you missing a using directive or an assembly reference?)"} System.Web.HttpCompileException

Edit 1

@model Carinas_Univers.Models.BlogItemViewModel
@{
    Layout = "Master.cshtml";
}

i have a view model, master page, and a master controller. the mastercontroller inherits from RenderMvcController

2

2 Answers

1
votes

Does your view inherit from UmbracoViewPage? If so then it sounds like it doesn't know what namespace UmbracoViewPage is in. The simple solution would be to change it to Umbraco.Web.Mvc.UmbracoViewPage.

0
votes

You should load your custom class along with the Umbraco view page.

Have you tried this?

@inherits UmbracoViewPage<Carinas_Univers.Models.BlogItemViewModel>

You need to get and load the current page within your controller in order to get the page properties and assign them to the model properties

To do that you can do the following:

var currentPageId =  UmbracoContext.Current.PageId;   
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent content = umbracoHelper.TypedContent(currentPageId);