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..
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:
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.
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 :
The error is on var textPageGrid
I am Getting This error:
I Hope there is someone that can help me figure this out..
Hi Andre
Are you sure that CurrentPage working properly?
Thanks,
Alex
How should i check this ?
Can you debug?
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..
trace error told something about line 22, do you know what there?
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.
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:
These approaches are considered obsolete. Use @Html.GetGridHtml.
i have seen them indeed, but haven't been able to make it work at all..
Can you try insert in your view:
This is my view now.
But i get the error does not contain a definition for getgridhtml.
What about this code:
Exactly the same error on GetGridHtml
Do you have needed references? really strange - it works for me
As far as i can see, i have the same references as my other project, which is also what i find so confusing...
Did you find some issues?
Maybe some caching, how are you running the website?
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.
Hi Andre
Did you solve this issue? Can you share with the community?
Thanks,
Alex
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. theUmbracoViewPage
class that you're missing, is located in theUmbraco.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 ;)
is working on a reply...