繁体   English   中英

带有 Ckeditor 5 和 ASP.NET MVC 包错误的 NullReferenceException?

[英]NullReferenceException with Ckeditor 5 and ASP.NET MVC bundle error?

为了隔离任何问题以便我可以重现该问题,我从 VS 2017 中的一个全新项目开始,该项目使用 ASP.NET MVC 模板 (.NET Framework 4.6.1)。

我将最新的 ckeditor5 添加到 /Scripts/ckeditor5/ckeditor.js

在 BundleConfig.cs 中,我添加了这个:

bundles.Add(new ScriptBundle("~/bundles/ckeditor").Include(
"~/Scripts/ckeditor5/ckeditor.js"));

在 _layout.cshtml 中,我有这个:

@Scripts.Render("~/bundles/ckeditor")

当我运行该应用程序时,出现“System.NullReferenceException”错误。 似乎微软 Ajax 解析不喜欢 ckeditor5??

at Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteralProperty(Boolean isBindingPattern)\r\n at Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteral(Boolean isBindingPattern)\r\n at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus) \r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseVarDecl(JSToken inToken)\r\n
在 Microsoft.Ajax.Utilities.JSParser.ParseVariableStatement()\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseFunctionBody(块体)\r\n
在 Microsoft.Ajax.Utilities.JSParser.ParseFunction(FunctionType functionType, Context fncCtx)\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(布尔值是负号)\r\n 在 Microsoft.88170420156P.JS.Utilities.881704201562SP Boolean& isLeftHandSideExpr, Boolean isMinus)\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseArrayLiteral(Boolean isBindingPattern)\r\n 在

如果我忘记 Bundle 并在 _Layout.cshtml 上硬编码这样的路径,它会起作用:

<script src="~/Scripts/ckeditor5/ckeditor.js"></script>

知道如何使 bundle 适用于 ckeditor5 吗?

这个问题很可能与 ScriptBundle 试图缩小已经缩小的文件有关。 在 Ckeditor5 的情况下,哪个中断了。

解决方法是将 .min 添加到文件扩展名 the.js 之前。

这为我解决了这个问题。

您不必使用 ScriptBundle 名称中的扩展文件。

不是这样的:

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js"));

像这样做:

在 BundleConfig.cs 上:

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap"));

在 file.cshtml 上:

@Scripts.Render("~/bundles/bootstrap")

我在这个页面上找到了这个: https://www.it-swarm-es.com/es/asp.net-mvc/mvc-bundling-no-se-pudo-cargar-el-recurso/1040501977/

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include("~/Scripts/bootstrap"));

使用此顶部栏后从主页消失,如 bootstrap 无法正常工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM