首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何修复Sitecore 9.3中渲染视图时出现的错误?

如何修复Sitecore 9.3中渲染视图时出现的错误?
EN

Stack Overflow用户
提问于 2021-08-26 14:05:34
回答 2查看 661关注 0票数 0

我目前正在学习一门关于Sitecore的课程,现在我被困在一个我找不到的名称空间上。我已经尝试将其添加到/Views和Web.cfg文件夹中的项目中。每次我尝试打开Experience Editor时,都会出现以下错误:

代码语言:javascript
运行
复制
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)

我的default.cshtml文件如下所示:

代码语言:javascript
运行
复制
@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>

EN

回答 2

Stack Overflow用户

发布于 2021-08-30 17:08:18

请确保渲染项(/sitecore/layout/Renderings/Your视图渲染项)正确填充了这两个字段:

  • Path:(Path/to/your/view.cshtml)
  • Model:(Path/to/your/model/ in /SitecoreTree)
    • 应该在那里: /sitecore/layout/Models

然后,确保模型项的字段模型类型也已正确填写

  • namespace.yourclass,程序集

另外,

cshtml确保您的cshtml可以在您的inetpub中找到: C:\inetpub\wwwroot\yourSite\Website\Views\ClothingCo\Layouts\default.cshtml

  • since错误指出:类型或命名空间名称‘
  • ’找不到,这使我怀疑您的default.cshtml的有效性。也许您没有编辑好的那个,因为它应该作为模型类型的using语句出现在您的视图中,或者直接出现在模型中。但是基于您的default.cshtml示例,没有对此模型的引用。可能您正在编辑或查看错误的位置。
  • 是否还能确保您尝试查看的项目已正确设置演示文稿详细信息?
    • 在内容编辑器上,单击您的项目。
    • 在导航中(具有从左到右的以下选项卡的灰色背景的导航:主页、导航、审阅...)单击下面导航中的Presentation Tab。
    • Now(白色背景的选项卡从左到右依次为: Save、Details、Reset、..)单击Details.
    • Make确保正在使用的布局是好的布局(应该是包含路径的布局项目: /Views/ClothingCo/Layouts/default.cshtml).

  • 确保控件中添加的呈现也有效。
票数 1
EN

Stack Overflow用户

发布于 2021-10-05 18:44:16

似乎你的视图的web.config以某种方式添加了BasicCompany,可能来自于你以前的项目发布?尝试将其从views web.config中删除,然后将解决方案重新发布到website文件夹。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68940081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档