我有一个模型:
[Required(ErrorMessage = "Dit veld is verplicht")]
[Range(60, 60000, ErrorMessage = "De waarde moet tussen de 60 en 60000 liggen")]
public double? Kilometers { get; set; }
[Required(ErrorMessage = "Dit veld is verplicht")]
public int? Minutes { get; set; }
还有我的html:
<div class="control-group container-trigger" id="container-distance">
<label class="control-label" for="trigger-distance">Aantal kilometers</label>
<div id="distance" class="controls">
@Html.TextBoxFor(m => m.Alert.Kilometers, new { id = "trigger-distance", @name = "trigger-distance" })
@Html.ValidationMessageFor(m => m.Alert.Kilometers, "", new { @class = "error-0" })
</div>
</div>
<div class="control-group container-trigger" id="container-minutes">
<label class="control-label" for="trigger-minutes">Aantal minuten</label>
<div id="minutes" class="controls">
@Html.TextBoxFor(m => m.Alert.Minutes, new { id = "trigger-minutes", @name = "trigger-minutes" })
@Html.ValidationMessageFor(m => m.Alert.Minutes, "", new { @class = "error-0" })
</div>
</div>
我有一个下拉列表,如果我做出选择,我需要它来显示一个文本框。如果我选择第一个选项,它将显示一个文本框几分钟。如果我选择第二个选项,那么它将显示一个距离文本框。我所拥有的是,如果我单击提交按钮,我会收到表单中未显示的文本框的验证错误,但只有在显示时才需要它们!
我能做些什么来解决这个问题?