JavaScript runtime error: Syntax error, unrecognized expression 0x800a139e

JavaScript runtime error: Syntax error, unrecognized expression 0x800a139e

我在我的 MVC 5 应用程序中遇到了这种奇怪的行为。

我有几个 Ajax.ActionLinks 的视图,它们在点击事件时加载相应的局部视图。

@Ajax.ActionLink("Some text here", "_ActionName", "ControllerName", new { param = Model.Id }, ajaxOptions: new AjaxOptions { UpdateTargetId = "partialViewContainer", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" }, htmlAttributes: new { @id = "btn" })

这成功加载了 _ActionName(int param)ControllerName.. 中返回的部分视图,但是,在 Chrome' s 控制台,它抛出异常 Uncaught Error: Syntax error, unrecognized expression: /ControllerName/_ActionName?param=12

所以问题出在 /ControllerName/_ActionName?param=12 表达式...

IE(所有版本)抛出相同的异常,但在一个烦人的弹出窗口中。

Visual Studio 配置为在所有 JavaScript 错误时中断,所以我猜这是预期的..但我不明白为什么 jQuery 会抛出此异常...它不喜欢 Razor 引擎生成的表达式。一些 post 建议降级到 1.x jQuery 版本,但这没有帮助。

我有其他 MVC 应用程序通过类似的方法加载部分视图 Ajax.ActionLinks 以前从未遇到过这个问题...

附加信息:

我正在使用 Visual Studio 2015 Pro

项目中使用的库:

如果还有什么我可以提供的,可以帮助您更好地理解,请告诉我。提前致谢!

编辑:

我尝试降级到 jQuery 1.7.2,但我不再遇到异常。 这是因为..

from the notes

Prior to 1.9, a string would be considered to be an HTML string if it had HTML tags anywhere within the string. This has the potential to cause inadvertent execution of code and reject valid selector strings. As of 1.9, a string is only considered to be HTML if it starts with a less-than ("<") character. The Migrate plugin can be used to restore the pre-1.9 behavior. If a string is known to be HTML but may start with arbitrary text that is not an HTML tag, pass it to jQuery.parseHTML() which will return an array of DOM nodes representing the markup. A jQuery collection can be created from this, for example: $($.parseHTML(htmlString)). This would be considered best practice when processing HTML templates for example.
Simple uses of literal strings such as $("<p>Testing</p>").appendTo("body") are unaffected by this change.
Bottom line: HTML strings passed to jQuery() that start with something other than a less-than character will be interpreted as a selector. Since the string usually cannot be interpreted as a selector, the most likely result will be an "invalid selector syntax" error thrown by the Sizzle selector engine. Use jQuery.parseHTML() to parse arbitrary HTML.

我不确定如何使用 parseHTML() 解析 Razor 引擎生成的 Ajax.ActionLink href link。此外,我想继续使用 jQuery 2.x,因为 Bootstrap.js 3.6 与低于 1.9 的 jQuery 版本不兼容...

最终没有使用@Ajax.ActionLink。而是按照@FilixMogilevsky

的建议使用纯 jQuery Ajax 调用

现在我有

<a href="" data="@Url.Action("_ActionName", "ControllerName", routeValues: new {param = Model.Id})" class="tabLinks">Some text here...</a>
<div id ="divPartialView">
</div>

在脚本块中我使用

$('.tabLinks').on('click', function() {    
    var url = $(this).attr('data');
    $.get(url, function(data) {
        $('#divPartialView').html(data);
    });
});