Hier ist meine Ansicht Code:Wie setze ich die Validierung nach Dropdown-Auswahl in MVC?
<div class="form-group-1">
@Html.LabelFor(model => model.device.HasAMC, htmlAttributes: new { @class = "control-label col-lg-4" })
@Html.EditorFor(model => model.device.HasAMC, new { htmlAttributes = new { @class = "form-control" } })
</div>
<div class="form-group-1" id="HasDate">
@Html.LabelFor(model => model.device.AMCExpiredDate, htmlAttributes: new { @class = "control-label col-lg-4" })
@Html.EditorFor(model => model.device.AMCExpiredDate, new { htmlAttributes = new { @class = "form-control", placeholder = "AMCExpireDate(MM/dd/yyyy)", required = "required", title = "Enter AMC Expire Date" } })
</div>
<button style="margin-left:33%;" class="btn btn-sm btn-primary col-lg-2 " type="button" name="action" onclick="javascript:Save(@ViewBag.DealerId);" value="SaveDeviceInfo"><strong>Save</strong></button>
In diesem I erforderliches Feld „AMCExpiredDate“ festlegen müssen, wie wenn der Wert von „HasAMC“ ausgewählt „true“ dann Validierung für erforderliches Feld anwenden und wenn es falsch ist, dann entfernen Validierung von "AMCExpiredDate".
Ist dies in MVC möglich? Bitte helfen Sie mir. Danke im Voraus.
eine [narrensicher] Betrachten (http://foolproof.codeplex.com /) '[RequiredIf]' oder ähnliches Validierungsattribut (oder Sie können Ihr eigenes schreiben) –
Mögliches Duplikat von [Conditio nale Validierung auf Modell in MVC] (http://stackoverflow.com/questions/17970584/conditional-validation-on-model-in-mvc) – Pete
tun Sie es einfach mit jquery, bei onchange-Ereignis, fügen Sie das Validierungsattribut zum Dropdown hinzu –