簡體   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