简体   繁体   English

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

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

To isolate any problems so I can reproduce the issue, I started with a brand new project in VS 2017 with the ASP.NET MVC Template (.NET Framework 4.6.1).为了隔离任何问题以便我可以重现该问题,我从 VS 2017 中的一个全新项目开始,该项目使用 ASP.NET MVC 模板 (.NET Framework 4.6.1)。

I added the latest ckeditor5 to /Scripts/ckeditor5/ckeditor.js我将最新的 ckeditor5 添加到 /Scripts/ckeditor5/ckeditor.js

In BundleConfig.cs, I added this:在 BundleConfig.cs 中,我添加了这个:

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

In _layout.cshtml, I have this:在 _layout.cshtml 中,我有这个:

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

When I run the application, it gives "System.NullReferenceException" error.当我运行该应用程序时,出现“System.NullReferenceException”错误。 It seems Microsoft Ajax parse doesn't like ckeditor5??似乎微软 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 at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)\r\n at Microsoft.Ajax.Utilities.JSParser.ParseVarDecl(JSToken inToken)\r\n 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
at Microsoft.Ajax.Utilities.JSParser.ParseVariableStatement()\r\n at Microsoft.Ajax.Utilities.JSParser.ParseFunctionBody(Block body)\r\n在 Microsoft.Ajax.Utilities.JSParser.ParseVariableStatement()\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseFunctionBody(块体)\r\n
at Microsoft.Ajax.Utilities.JSParser.ParseFunction(FunctionType functionType, Context fncCtx)\r\n at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)\r\n at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)\r\n at Microsoft.Ajax.Utilities.JSParser.ParseArrayLiteral(Boolean isBindingPattern)\r\n at在 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 在

If I forget about Bundle and I hard code the path like this on _Layout.cshtml, it worked:如果我忘记 Bundle 并在 _Layout.cshtml 上硬编码这样的路径,它会起作用:

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

Any idea how to make bundle works for ckeditor5?知道如何使 bundle 适用于 ckeditor5 吗?

This issue most probably has to do with the ScriptBundle trying to Minify a file which was already minified.这个问题很可能与 ScriptBundle 试图缩小已经缩小的文件有关。 Which in the case of the Ckeditor5 breaks.在 Ckeditor5 的情况下,哪个中断了。

The fix was to add.min to the file extension before the.js.解决方法是将 .min 添加到文件扩展名 the.js 之前。

This fixed the issue for me.这为我解决了这个问题。

You don't have to use the extension file in the name of ScriptBundle.您不必使用 ScriptBundle 名称中的扩展文件。

Not like this:不是这样的:

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

Do it like this:像这样做:

On BundleConfig.cs:在 BundleConfig.cs 上:

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

On file.cshtml:在 file.cshtml 上:

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

I found this on this page: https://www.it-swarm-es.com/es/asp.net-mvc/mvc-bundling-no-se-pudo-cargar-el-recurso/1040501977/我在这个页面上找到了这个: 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"));

After using this Top bar Disappeared from Homepage like bootstrap does not working properly使用此顶部栏后从主页消失,如 bootstrap 无法正常工作

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

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