Copied to clipboard

Flag this post as spam?

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


  • André Lange 108 posts 410 karma points
    Aug 30, 2017 @ 11:53
    André Lange
    0

    Error when rendering grid

    Hi, i am getting an annoying error, when trying to render an umbraco grid..

    I have another solution where it works perfectly and exactly as this solution is made.

    i am running umbraco 7.6

    my code:

    My Controller :

    namespace Carinas_Univers.Controllers
    {
        public class TextPageController : MasterController
        {
            // GET: TextPage
            public ActionResult TextPage()
            {
                var model = new TextPageViewModel();
    
                //GridDataModel grid = CurrentPage.GetPropertyValue<HtmlString>("textPageGrid");
                // GET grid 1
                var textPageGrid = CurrentPage.GetGridHtml(DocTypes.TextPage.TextPageGrid);
                //add to model.
                model.TextPageGrid = new HtmlString(textPageGrid.ToHtmlString());
    
    
                return View(model);
            }
        }
    }
    

    The error is on var textPageGrid

    I am Getting This error:

    System.Web.HttpCompileException occurred
      HResult=0x80004005
      Message=c:\Users\André\AppData\Local\Temp\Temporary ASP.NET Files\vs\64b53191\7c93a364\App_Web_bootstrap3.cshtml.8bbe1d5f.9f_71e4c.0.cs(44): error CS0246: The type or namespace name 'UmbracoViewPage' could not be found (are you missing a using directive or an assembly reference?)
      Source=System.Web
      StackTrace:
       at System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.GetCompiledType(String virtualPath)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
       at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
       at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
       at Umbraco.Web.GridTemplateExtensions.GetGridHtml(HtmlHelper html, IPublishedContent contentItem, String propertyAlias, String framework)
       at Umbraco.Web.GridTemplateExtensions.GetGridHtml(IPublishedContent contentItem, String propertyAlias, String framework)
       at Umbraco.Web.GridTemplateExtensions.GetGridHtml(IPublishedContent contentItem, String propertyAlias)
       at Carinas_Univers.Controllers.TextPageController.TextPage() in C:\Users\André\Dropbox\Carinas Univers\Carinas Univers\Controllers\TextPageController.cs:line 22
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
    

    I Hope there is someone that can help me figure this out..

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Aug 30, 2017 @ 12:18
    Alex Skrypnyk
    0

    Hi Andre

    Are you sure that CurrentPage working properly?

    Thanks,

    Alex

  • André Lange 108 posts 410 karma points
    Aug 30, 2017 @ 12:19
    André Lange
    0

    How should i check this ?

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Aug 30, 2017 @ 12:19
    Alex Skrypnyk
    0

    Can you debug?

  • André Lange 108 posts 410 karma points
    Aug 30, 2017 @ 12:21
    André Lange
    0

    i guess yes ? But how do i determine if it works "correct" ?

    Edit

    As far as i can see it should work correctly, i can access properties like bodytext and such without issue..

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Aug 30, 2017 @ 12:25
    Alex Skrypnyk
    0

    trace error told something about line 22, do you know what there?

  • André Lange 108 posts 410 karma points
    Aug 30, 2017 @ 12:28
    André Lange
    0

    as far as i can see it is : var textPageGrid. Where it errors out. Which is also where i am trying to get the grid property.

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Aug 30, 2017 @ 12:31
    Alex Skrypnyk
    0

    Andre, did you read this - https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/grid-layout/render-grid-in-template

    Finally the Html.GetGridHtml helpers are the recommended approach for rendering grid properties in templates, however you may see in grid examples or discover in your existing site 'legacy code' when using the 'dynamic' CurrentPage approach for working with Umbraco templates and grid properties:

    @CurrentPage.GetGridHtml(Html, "propertyAlias")
    @CurrentPage.GetGridHtml(Html, "propertyAlias", "bootstrap2")
    @CurrentPage.GetGridHtml(Html, "propertyAlias", "mycustomrenderer")
    @CurrentPage.GetGridHtml(Html, "propertyAlias", "/views/mycustomrenderer.cshtml")
    

    These approaches are considered obsolete. Use @Html.GetGridHtml.

  • André Lange 108 posts 410 karma points
    Aug 30, 2017 @ 12:33
    André Lange
    0

    i have seen them indeed, but haven't been able to make it work at all..

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Aug 30, 2017 @ 12:34
    Alex Skrypnyk
    0

    Can you try insert in your view:

    @Html.GetGridHtml(DocTypes.TextPage.TextPageGrid)?
    
  • André Lange 108 posts 410 karma points
    Aug 30, 2017 @ 12:37
    André Lange
    0

    This is my view now.

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Carinas_Univers.Models.TextPageViewModel>
    
    @{
        Layout = "Master.cshtml";
    }
    
    <!-- Main -->
    <div class="main">
        <h1>Velkommen til TextPage Dokumentet.</h1>
    
    
        <!-- Grid Layout here -->
    
        @Html.GetGridHtml(DocTypes.TextPage.TextPageGrid)
    
    </div>
    @Html.Partial("_Sidebar")
    

    But i get the error does not contain a definition for getgridhtml.

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Aug 30, 2017 @ 12:38
    Alex Skrypnyk
    0

    What about this code:

    @Html.GetGridHtml(Umbraco.AssignedContentItem, "propertyAlias")
    
  • André Lange 108 posts 410 karma points
    Aug 30, 2017 @ 12:40
    André Lange
    0

    Exactly the same error on GetGridHtml

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Aug 30, 2017 @ 12:41
    Alex Skrypnyk
    0

    Do you have needed references? really strange - it works for me

  • André Lange 108 posts 410 karma points
    Aug 30, 2017 @ 12:42
    André Lange
    0

    As far as i can see, i have the same references as my other project, which is also what i find so confusing...

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Aug 30, 2017 @ 13:29
    Alex Skrypnyk
    0

    Did you find some issues?

    Maybe some caching, how are you running the website?

  • André Lange 108 posts 410 karma points
    Aug 31, 2017 @ 05:44
    André Lange
    0

    I am running the website locally with a database running locally as well on management studio 2017.

    I have tried removing everything in app_data, without any success.

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Oct 02, 2017 @ 10:03
    Alex Skrypnyk
    0

    Hi Andre

    Did you solve this issue? Can you share with the community?

    Thanks,

    Alex

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Oct 02, 2017 @ 12:11
    Anders Bjerner
    1

    Your views are most likely located in the ~/Views/ folder (or a sub folder), and as such they need ~/Views/Web.config to work properly. Are you by any chance missing this file? I think I've seen similar errors when this particular Web.config file hasn't been deployed to the live server.

    To explain it a little bit further, ~/Views/Web.config comes with Umbraco and is responsible for setting the namespaces that ASP.NET should import by default in your views - eg. the UmbracoViewPage class that you're missing, is located in the Umbraco.Web.Mvc namespace, which should be imported by default.

    Should your views are located elsewhere, you should probably add a similar Web.config file in that folder - or import the namespaces manually.

    I hope that helps ;)

Please Sign in or register to post replies

Write your reply to:

Draft