我有jquery包:
bundles.Add(new ScriptBundle("~/bundle/jquery").Include(
ScriptsPath("jquery-2.0.3.js"),
ScriptsPath("jquery.validate.js"),
ScriptsPath("jquery.validate.unobtrusive.js"),
ScriptsPath("jquery-ui-1.10.3.js"),
ScriptsPath("jquery.validate.unubtrusive.config.js"),
ScriptsPath("jquery.easing.1.3.js "),
ScriptsPath("jquery.unobtrusive-ajax.min.js"),
ScriptsPath("jquery.validate.custom.attributes.js") ...
在用户注册页面上,我同时拥有登录和注册表单,因此表单输入的名称中包含Register.
和Login.
前缀。基本上它看起来像:
<input type="text" ... id="Register_Email" name="Register.Email" />
<input type="password" ... id="Register_Password" name="Register.Password" />
当我在发布模式下发布我的应用程序时,我在捆绑文件中收到此错误:
这显然是因为输入名称中的点。如何保存点并解决此问题?我已经尝试BundleTable.EnableOptimizations = false;
,但它没有帮助,我不认为这是合适的解决方案,因为它消灭了捆绑的目的。另请注意,问题仅在发布模式下进行。
编辑:
Bundle文件列表包含我自己的一个脚本文件,它包含我ForbidHtmlAttribude
的客户端验证逻辑:
jquery.validate.custom.attributes.js
jQuery.validator.unobtrusive.adapters.add(
'forbidhtmlattribute',
['htmlregexpattern'],
function (options) {
options.rules['forbidhtmlattribute'] = options.params;
options.messages['forbidhtmlattribute'] = options.message;
}
);
jQuery.validator.addMethod('forbidhtmlattribute', function (value, element, params) {
if (value === null || value === undefined) return true;
var regex = params['htmlregexpattern'];
return !value.match(regex);
}, '');
答案 0 :(得分:4)
最有可能的问题是这一行:
if (value === null || value === undefined) return true;
尝试将其更改为
if ((value === null) || (value === undefined)) return true;
<强> Exaplanation:强>
MS缩小算法删除不必要的空格。它“知道”语言关键字,如“var”或“return”,但“null”不是其中之一。因此,缩小的行将是
if(value===null||value===undefined)return true;
现在从JavaScript的角度来看,我们有一个名为“null||value
”的奇怪变量。括起括号中的条件可以解决问题:
if(value===null)||(value===undefined)return true;