数据范围注释未正常工作,任何想法? [英] Range data annotation is not working as expected, any idea?

查看:69
本文介绍了数据范围注释未正常工作,任何想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我假设的验证检查将允许来自任何1输入值30。但是,它会提示输入错误,当我输入,在这一领域的4到9的值。任何建议?请...

I assume the validation check will allow any input value from 1 to 30. But, it prompts for error when I input a value with 4 to 9 in this field. Any advise? Please...

备注:我的项目是根据MVC4 Web应用程序+的Razor视图引擎+ C#.NET

remarks: My project is based on "MVC4 Web Application + Razor View Engine + C# .net".

using System.ComponentModel.DataAnnotations;

[Range(1, 30, ErrorMessageResourceType = typeof(Resources.ErrorMessage), ErrorMessageResourceName = "RangeErrorMsg")]
public int HowManyDays { get; set; }

下面是我的Razor视图源

Below is my Razor view source

<div class="editor-label">
    @Resources.Booking.Duration
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.HowManyDays)
    @Html.ValidationMessageFor(model => model.HowManyDays)
</div>

我没有办法上传我的屏幕转储,因为我至少需要10声誉这样做。奇怪,这显示了在4至9只看重警报。顺便说一句,我安装了DataAnnotationsExtensions.MVC3的NuGet包。不过,我曾尝试解除停止它没有运气。

I have no way to upload my screen dump as I need at least 10 reputation to do so. Weird, it shows alert for value in range of 4 to 9 ONLY. Btw, I have "DataAnnotationsExtensions.MVC3" NuGet package installed. But, I did try to unstalled it without luck.

推荐答案

您在 EditorFor 第二个参数没有任何意义。
看看 EditorFor帮助或只是其对SO(本网站)使用的例子。
这可能伤了你的观点,你会得到任何验证。
首先,只是删除逗号和数字,看看有没有什么工作,如果不看关于如何使用示例 EditorFor

Your second argument in EditorFor doesn't make any sense. Take a look at EditorFor help or just on examples of its use on SO (this site). This probably breaks your view and you get no validation. To begin with, just remove the comma and the number, see if that works, if not look for examples on how to use EditorFor.

修改

您的评论使我的答案完全不相干。你应该准确为你把什么公众看到。
无论如何,尝试看看是否成功这个问题的回答能解决您的问题:
<一href=\"http://stackoverflow.com/questions/3480140/range-dataannotation-doesnt-seem-to-be-working-in-net-3-5\">Range DataAnnotation似乎并不奏效

Your comment renders my answer completely irrelevant. You should be accurate as to what you put for public to see. Anyway, try to see if this successfully answered question solves your problem: Range DataAnnotation Doesn't Seem to Be Working

请让我知道如果这有助于。
谢谢你。

Please let me know if this helps. Thanks.

这篇关于数据范围注释未正常工作,任何想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆