Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Make the following Change : - </p> </blockquote> <p>1.Your ViewModel : - </p> <pre><code>Public Class ViewModel &lt;SelectOne()&gt; &lt;SelectOneProperty(TargetValue:=True, ErrorMessage:="Select at least one.")&gt; Public Property Collection As List(Of Item) End Class </code></pre> <ol> <li><p>My Model : -</p> <p>Public Class Item Public Property Selected As Boolean Public Property Value As String End Class</p></li> <li><p>On your View Add the following line :</p> <p>@Html.HiddenFor(x=>x.ItemCollection)</p></li> </ol> <p>4.then you will run the view and see the view source then it will </p> <p></p> <p>4.And then you will submit the code then it will run client-side validation. add the debugger and Debug it </p> <p>5.And then modify the your client side script. 1.Now you can fetch the value from every check box and check that any of of your check box is selected then submit the form otherwise display the result.</p> <p>6.Also Make change in SelectOnePropertyAttribute as per your requirement</p> <p>7.And for Server Side I have done this code on c# : - </p> <p>[AttributeUsage((AttributeTargets.Field | AttributeTargets.Property), AllowMultiple = false, Inherited = false)] public class SelectOneAttribute : ValidationAttribute { public String PropertyName { get; set; }</p> <pre><code> protected override ValidationResult IsValid(object value, ValidationContext validationContext) { bool boolVal = false; IList list; if (value == null) { return null; } if (value.GetType().Name == typeof(List&lt;&gt;).Name || value.GetType().Name == typeof(IList&lt;&gt;).Name) { list = (IList)value; } else { list = new object[] {value}; } if (list.Count&lt;0) return null; if ((from object item in list let propertyInfo = item.GetType().GetProperties() from info in propertyInfo where String.Equals(info.Name, PropertyName) &amp;&amp; (bool)info.GetValue(item) == true select item).Any()) { return null; } return new ValidationResult(FormatErrorMessage(validationContext.DisplayName)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload