小编use*_*835的帖子

MVC 4自定义验证属性在服务器端触发两次

我正在使用自Required继承的自定义验证requiredconditional,以有条件地需要某些字段。除非有一次,这种方法在任何地方都可以很好地工作,我无法弄清楚发生了什么。它为模型中的一个属性调用两次IsValid方法(客户端验证工作正常)。模型使用此属性具有2个属性,但只有一个存在问题。最初,我认为这是因为我的条件之一是一个复选框,并且它同时回发了已检查的值和隐藏的值,但是我尝试使用单选按钮代替,甚至使用隐藏的值,但在所有情况下都具有相同的结果。这是我的观点(简化测试):

@ModelType List(Of eLADNETBusiness.AdditionalInterest)

@Code
    ViewData("Title") = "Bind Coverage Entry"
End Code

<h2>Bind Coverage Entry</h2>
@Using Html.BeginForm()
    @Html.AntiForgeryToken() 
    @Html.Hidden("hullValue", ViewBag.HullValue)
    Dim currentCount As Integer = 0
    @For count As Integer = 0 To Model.Count - 1
            currentCount = count
             @<div class="editor-label">
                 @Html.LabelFor(Function(model) model(currentCount).LienholderAmount)
              </div>
             @<div class="editor-field">
                @Html.EditorFor(Function(model) model(currentCount).LienholderAmount)
                @Html.ValidationMessageFor(Function(model) model(currentCount).LienholderAmount)
             </div>
             @<div>
                @Html.EditorFor(Function(model) model(currentCount).Lienholder90Percent)
             </div>
     Next
    @<p>
        <input type="submit" value="Continue" />
    </p>

End Using
Run Code Online (Sandbox Code Playgroud)

这是我的模型(简化测试):

<DataContract()> _
Public Class AdditionalInterest
<DataMember()> _
Public Property ID As Integer = 0 

<RequiredConditional("Lienholder90Percent", …
Run Code Online (Sandbox Code Playgroud)

validation asp.net-mvc

2
推荐指数
1
解决办法
1309
查看次数

标签 统计

asp.net-mvc ×1

validation ×1