首页 \ 问答 \ 使用Spring.net进行xVal验证(xVal validation with Spring.net)

使用Spring.net进行xVal验证(xVal validation with Spring.net)

我已经开始使用xVal作为ASP.Net MVC应用程序的验证框架。 我使用Spring.Net IoC容器将应用程序保存在一起。

我按照Steve Sanderson博客上的说明进行操作,以使服务器端验证工作正常。 但是当我尝试让客户端工作时,我得到以下运行时异常:

Spring.Objects.Factory.NoSuchObjectDefinitionException was unhandled by user code

Message =“没有定义名为'Scripts'的对象:找不到对象[Scripts]的定义”

我认为这是因为Site.Masterpage中包含以下代码:

<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery-1.2.6.js")%>"></script>
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.validate.js")%>"></script>
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/xVal.jquery.validate.js")%>"></script>

哪个尝试解决〜/ Scripts /使用Spring。

如何让Spring处理这个问题(即配置XML中的内容),或者我在Site.Master中更改了什么,这样就不会发生这种情况?


I have started to play with xVal as my validation framework for an ASP.Net MVC application. I use the Spring.Net IoC container to hold the app together.

I have followed the instructions on Steve Sanderson's blog to get server side validation working fine. But when I try to get client side working, I get the following runtime exception:

Spring.Objects.Factory.NoSuchObjectDefinitionException was unhandled by user code

Message="No object named 'Scripts' is defined : Cannot find definition for object [Scripts]"

I presume this is because the Site.Masterpage has the following code in it:

<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery-1.2.6.js")%>"></script>
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.validate.js")%>"></script>
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/xVal.jquery.validate.js")%>"></script>

Which is trying to resolve ~/Scripts/ using Spring.

How do I get either Spring to cope with this (i.e. what goes into the config XML), or what do I change in Site.Master so this does not happen?


原文:https://stackoverflow.com/questions/827091
更新时间:2022-10-06 15:10

最满意答案

两者之间确实没有区别,但编译器在涉及到浮点计算时习惯于采取一些自由度。 例如,编译器可以自由使用更高的精度来计算中间结果,但更高的结果仍然意味着不同,因此结果可能会有所不同。

有些编译器提供的开关总是会降低额外的精度,并将所有中间结果转换为规定的浮点数(比如64位双精度数)。 然而,这会使代码变慢。

在具体的数字45.33不能完全用浮点值表示(这是一个二进制表示的周期数,它将需要无限的位数)。 当乘以100这个值可能是你没有得到一个整数,但是非常接近的东西(正好在下面或正上方)。

int转换或铸造是使用截断和非常接近4533但以下将成为4532 ,当上述将成为4533 ; 即使这种差异非常小,比如说1E-300

为避免出现问题,请务必考虑数字精度问题。 如果你正在做一个依赖于浮点数的确切值的计算,那么你正在使用错误的工具。


There is indeed no difference between the two, but compilers are used to take some freedom when it comes down to floating point computations. For example compilers are free to use higher precision for intermediate results of computations but higher still means different so the results may vary.

Some compilers provide switches to always drop extra precision and convert all intermediate results to the prescribed floating point numbers (say 64bit double-precision numbers). This will make the code slower, however.

In the specific the number 45.33 cannot be represented exactly with a floating point value (it's a periodic number when expressed in binary and it would require an infinite number of bits). When multiplying by 100 this value may be you don't get an integer, but something very close (just below or just above).

int conversion or cast is performed using truncation and something very close to 4533 but below will become 4532, when above will become 4533; even if the difference is incredibly tiny, say 1E-300.

To avoid having problems be sure to account for numeric accuracy problems. If you are doing a computation that depends on exact values of floating point numbers then you're using the wrong tool.

相关问答

更多
  • 转换为int隐式删除任何小数。 不需要调用Math.floor()(假定正数) (int)简单的typecast,例如: System.out.println((int)(99.9999)); // Prints 99 话虽如此,它确实与Math.floor行为不同,后者向负无穷大转变(@Chris Wong) Casting to an int implicitly drops any decimal. No need to call Math.floor() (assuming positive nu ...
  • 您可以使用std::stringstream 。 #include #include #include using namespace std; int main(void) { double var = 1.0000001; cout << setprecision(10)<< var << endl; stringstream ss; ss << setprecision(10) << var; st ...
  • 您的方法签名表明您在实际返回double时返回int。 您可以通过将签名更改为: static double compoundBalance(double db, double dbTwo, double dbThree) { 当你打算返回6.9时,这个错误就是阻止你返回类似6的东西。 如果您确实需要此行为,则可以将返回值强制转换为int,而不是更改签名。 static int compoundBalance(double db, double dbTwo, double dbThree) { if( ...
  • 两者之间确实没有区别,但编译器在涉及到浮点计算时习惯于采取一些自由度。 例如,编译器可以自由使用更高的精度来计算中间结果,但更高的结果仍然意味着不同,因此结果可能会有所不同。 有些编译器提供的开关总是会降低额外的精度,并将所有中间结果转换为规定的浮点数(比如64位双精度数)。 然而,这会使代码变慢。 在具体的数字45.33不能完全用浮点值表示(这是一个二进制表示的周期数,它将需要无限的位数)。 当乘以100这个值可能是你没有得到一个整数,但是非常接近的东西(正好在下面或正上方)。 int转换或铸造是使用截断 ...
  • 4.35不能精确地表示为浮点数,因为.35不是2的(负)幂。因此,有一些方法可以这样或那样。 当你乘以100时,可能还会有舍入。如果得到的数字小于435,则转换为int将占用它的最低值,即434。 如果你想舍入到NEAREST整数,你可以在结果中加0.5,然后转换为int。 尽管Java具有内置的舍入实现,但这是舍入数字的最常用方法。 double f = 4.35; int n = (int) (100 * f + 0.5); 4.35 cannot be represented exactly a ...
  • 您想使用BigDecimal以保持精度。 BigInteger myBI = new BigInteger("99999999999999999"); Double d = 0.123; BigDecimal bd = new BigDecimal(myBI); BigDecimal result = bd.multiply(BigDecimal.valueOf(d)); Using BigDecimal indeed works. You still have to be carefull about ...
  • 链接中的代码与最初在此处发布的代码之间存在一个小但重要的区别, meaning += Math.random() + 1; // link 与 meaning += (int)Math.random() + 1; // StackOverflow 如果这里发布的代码打印出除42之外的任何内容,那么这是一个严重的错误。 这里, Math.random()的结果显式地转换为int , 必须得到0,然后添加1,得到1,然后将其添加到meaning 。 然而,在将Math.random()的结果添加到1 ...
  • 我知道给定字符串的类型但我不能使用strtoll,因为数字是用科学记数法给出的。 您只需要调用一次,使用结果指针来检测该数字是否为xxxeyyy形式,并再次调用strtoll来解析指数。 在我看来,比通过浮点更简单。 我知道这个数字足够长,可以用双精度正确表示。 不,您不知道,因为您的示例输入是“123456789012345678”,这在IEEE 754双精度中无法表示。 我可以使用长双,但这不会解决问题。 实际上,如果你的编译器将long double映射到“具有64位有效数字的80位扩展精度”,它将解 ...
  • 当你使用Int()它会强制你的数字被截断,总是向零逼近。 因此,6.9999变成了6而不是7,因为它接近零。 如果你首先使用round()它应该有所帮助: var steps: Int { return Int(round((max - min) / step) + 1.0) } When you use Int() it forces truncation of your number, which always rounds towards zero. So, 6.9999 becomes 6 ...
  • 您展示的任何替代方案都没有给出任何精度损失[至少不是编译器执行标准所说的应该做的事情]。 这是所有二元运算符,其中一个操作数是double ,另一方自动升级为double [并且通常,当两个操作数大小不同时,它们被提升为更大的操作数]。 特别是,始终精确地表示整数值[低于尾数的位数]。 [显然,我们不知道calc对你的输入做了什么 - 这可能是任何和各种错误的根源,但我假设你实际上在询问你建议的情况下3.0/8.0是否总是0.375 - 当然3/8会导致零,因为两边都是整数] 编辑以响应正在编辑的原始问题: ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)