How do I fix the Error Rendering View in Sitecore 9.3?

4.2k Views Asked by At

I'm currently following a course on Sitecore and I'm now stuck on a namespace I can't find. I've tried to add this to the Web.cfg both in the /Views and Project file folder. Every time I try to open up the Experience Editor it gives me the following error:

Error Rendering View: /Views/ClothingCo/Layouts/default.cshtml: Error while rendering view: '/Views/ClothingCo/Layouts/default.cshtml' (model: 'Sitecore.Mvc.Presentation.RenderingModel, Sitecore.Mvc').
   at Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer)
   at Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args)
Inner Exception: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET     Files\root\16344e6a\1fed4132\App_Web_default.cshtml.25717ab2.1h7yetdm.0.cs(39): error CS0246: The     type or namespace name 'BasicCompany' could not be found (are you missing a using directive or an     assembly reference?)
   at System.Web.Compilation.BuildManager.PostProcessFoundBuildResult(BuildResult result,     Boolean keyFromVPP, VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetBuildResultFromCacheInternal(String cacheKey,     Boolean keyFromVPP, VirtualPath virtualPath, Int64 hashCode, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultFromCacheInternal(VirtualPath     virtualPath, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath,     Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound,     Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context,     VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile,     Boolean throwIfNotFound, Boolean ensureIsUpToDate)
   at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath,     HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
   at System.Web.Compilation.BuildManager.GetCompiledType(VirtualPath virtualPath)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String     partialViewName, Object model, ViewDataDictionary viewData)
   at Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer)

My default.cshtml file looks like this:

@using Sitecore.Mvc @using Sitecore.Mvc.Analytics.Extensions @using Sitecore.Mvc.Presentation @model RenderingModel @{ Layout = null; }
<!DOCTYPE html>
<html>

<head>
  <title>@Html.Sitecore().Field("Page Title", new { DisableWebEdit = true })</title>
  @Html.Sitecore().VisitorIdentification()
</head>

<body>
  <h1>@Html.Sitecore().Field("Page Title")</h1>
  <div>
    @Html.Sitecore().Placeholder("main")
  </div>
</body>

</html>

2

There are 2 best solutions below

0
Jean-Nicolas G. On

Make sure that the rendering item (/sitecore/layout/Renderings/Your View rendering Item) has both of these fields correctly filled :

  • Path : (Path/to/your/view.cshtml)
  • Model : (Path/to/your/model-item/in/SitecoreTree)
    • Should be in there : /sitecore/layout/Models

Then, make sure your model item's field Model Type is also correctly filled

  • namespace.yourclass, assembly

Also,

  • make sure that your default.cshtml can be found in your inetpub there : C:\inetpub\wwwroot\yourSite\Website\Views\ClothingCo\Layouts\default.cshtml
  • since the error points out this : type or namespace name 'BasicCompany' could not be found, it makes me question your cshtml validity. Maybe your not editing the good one because it should be either in your view as a using statement for the model type, or within the model directly. But based on your default.cshtml example, there are no reference to this model. Perhaps you are editing or looking at the wrong place.
  • Can you also make sure that the item you are trying to view has the presentation details properly setup ?
    • On the content editor, click on your item.
    • Within the navigation (the one with grey background that has these tabs from left to right : Home, Navigate, Review, ...) click on Presentation Tab.
    • Now, within the navigation just below (the one with white background that has these tabs from left to right : Save, Details, Reset, ..) click on Details.
    • Make sure the layout being used is the good one (should be the layout item that hold the Path : /Views/ClothingCo/Layouts/default.cshtml).
  • Make sure the rendering added within the controls are valid as well.
0
Prabhu Ramesh On

It seems that the web.config of your views has the BasicCompany added somehow, may be from your previous project publishes? Try to remove it from views web.config and republish the solution to website folder.