You can use jQuery to achieve this. First delete the Model class validation. Then try the following code.
<form>
<div class="form-group row">
<div class="col-sm-4">
<label asp-for="HomePhone" class="control-label" style="font-weight:bold;"></label>
<input asp-for="HomePhone" id="HomePhoneInput" class="form-control input-lg" placeholder="(___) ___-____" data-slots="_" />
</div>
<div class="col-sm-4">
<label asp-for="WorkPhone" class="control-label" style="font-weight:bold;"></label>
<input asp-for="WorkPhone" id="WorkPhoneInput"class="form-control input-lg" placeholder="(___) ___-____" data-slots="_" />
</div>
<div class="col-sm-4">
<label asp-for="CellPhone" class="control-label" style="font-weight:bold;"></label>
<input asp-for="CellPhone" id="CellPhoneInput" class="form-control" placeholder="(___) ___-____" data-slots="_" />
</div>
</div>
<div class="form-group" style="margin-top:20px">
<alert></alert>
<input style="float: right; margin-bottom:20px" type="submit" id="myBtn1" value="Submit" class="btn btn-primary" />
</div>
</form>
@section Scripts {
@{
<script type="text/javascript">
$(document).ready(function () {
$('#myBtn1').click(function (event) {
if ((document.getElementById("HomePhoneInput").value == "")&&
(document.getElementById("WorkPhoneInput").value == "") &&
(document.getElementById("CellPhoneInput").value == "")){
$('alert').html("At least one number is required").css('color', 'red');
event.preventDefault();
}
});
});
</script>
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Jerry Fu