Use custom validation.
Refer below sample.
Custom Validation Class
using System.ComponentModel.DataAnnotations;
public class AtLeastOnePropertyAttribute: ValidationAttribute
{
public override bool IsValid(object value)
{
var typeInfo = value.GetType();
var propertyInfo = typeInfo.GetProperties();
foreach (var property in propertyInfo)
{
if (null != property.GetValue(value, null))
{
return true;
}
}
return false;
}
}
Model
[AtLeastOneProperty(ErrorMessage = "You must enter at least one Phone Number.")]
public class PersonModel
{
public string Ph1 { get; set; }
public string Ph2 { get; set; }
public string Ph3 { get; set; }
}
Controller
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Index(PersonModel person)
{
if (ModelState.IsValid)
{
}
return View();
}
}
View
@model RadioButton_Validation_MVC_Core.Models.PersonModel
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<style type="text/css">
body { font-family: Arial; font-size: 10pt; }
.error { color: red; }
</style>
</head>
<body>
<form method="post" asp-controller="Home" asp-action="Index">
<table>
<tr>
<td>Phone 1: <input type="text" asp-for="Ph1" /></td>
</tr>
<tr>
<td>Phone 2: <input type="text" asp-for="Ph3" /></td>
</tr>
<tr>
<td>Phone 3: <input type="text" asp-for="Ph2" /></td>
</tr>
<tr>
<td><div asp-validation-summary="ModelOnly" class="error"></div></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
Screenshot