0

我完全对这个荒谬的问题感到困惑,但我必须解决。 我有一个领域,我设置所需和范围验证就可以了:MVC中的范围验证只显示默认消息

[Required(ErrorMessage = ValidationMessage.InputDataStart + Field.SmtpPort + ValidationMessage.InputDataEnd)]   
[Range(FieldSize.PortNumberMin, FieldSize.PortNumberMax, ErrorMessage = ValidationMessage.InputDataIsOutOfRangeStart + Field.SmtpPort + ValidationMessage.InputDataIsOutOfRangeEnd)] 
public int SmtpPort { get; set; }  

这是NumericBox的代码:

<div class="Component-Container-Border" style="@BorderWidth"> 
<div class="Component-Label" style="@LabelOfComponentWidth">@Html.DisplayNameFor(model => model)</div> 
<div class="Component-Container-ComponentAndValidation" style="float:right;margin-bottom:0px;"> 
    @Html.TextBoxFor(m => m, new { type = "text", Class = "k-textbox", Value = Value, style = ComponentWidth + ";direction:ltr;border:1px solid #df795a;font-family:MasterFont,tahoma;", MaxLength = Len, Min = MinValue, Max = MaxValue })   
    <script> 
     $("#@FieldName").on("keydown",function(e) {OnKeyDownIntegerNumber(e)}); 
     $("#@FieldName").on("input change keypress",function(e) { 
      $(e.target).valid(); 
     }); 
    </script> 
</div> 
<div style="float:right;"> 
    <input id="ButtonPlus" type="Button" value="+" class="k-button" style="width: 28px; margin: 2px 2px 1px 0px; padding: 0px; height: 26px;font-size: 13px;" onclick="ButtonPlusClick(this, @MaxValue)" /> 
</div> 
@if (Unit.Trim() != "") 
{ 
    <div style="float:right;"> 
     <input id="ButtonMinus" type="Button" value="-" class="k-button" style="width: 28px; margin: 2px 2px 1px 0px; padding: 0px; height: 26px; font-size: 13px;" onclick="ButtonMinusClick(this, @MinValue)" /> 
    </div> 
    <span style="float:right;margin-right:5px;margin-top:5px;">@Unit</span> 
} 
else 
{ 
    <div> 
     <input id="ButtonMinus" type="Button" value="-" class="k-button" style="width: 28px; margin: 2px 2px 1px 0px; padding: 0px; height: 26px; font-size: 13px;" onclick="ButtonMinusClick(this, @MinValue)" /> 
    </div> 
} 
<div style="height:19px;"> 
@Html.ValidationMessageFor(model => model, "", new { @class = "Component-Validation-Message"}) 
</div> 

但是,当我输入一个数字,出范围,验证显示我的默认范围消息,而不是我的自定义消息。

这样的: Showing default message of range validation

这是检验我的文本框和JavaScript文件 inspect and javascripts

所以,在这里我可能是错的,因为这些消息显示不正确?

+0

是否为该项目启用了不显眼的验证?如果是这样,你可能需要扩展jQuery的validate插件,你也可以提供一个浏览器的图片检查元素与生成的数据属性。 –

+0

感谢您的考虑,但其他验证(例如required或StringLength)正常工作 –

回答

0

我终于找到了我的问题,有人提到这条线:

@Html.TextBoxFor(m => m, new { type = "text", Class = "k-textbox", Value = Value, style = ComponentWidth + ";direction:ltr;border:1px solid #df795a;font-family:MasterFont,tahoma;", MaxLength = Len, Min = MinValue, Max = MaxValue }) 

当我使用的最小和最大属性,范围验证只鞋缺省消息,我改成这样:

@Html.TextBoxFor(m => m, new { type = "text", Class = "k-textbox", Value = Value, style = ComponentWidth + ";direction:ltr;border:1px solid #df795a;font-family:MasterFont,tahoma;", MaxLength = Len})