Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:25:47+00:00 2026-05-29T13:25:47+00:00

In my VIew ive got 3 checkboxes, i want to validate them that way

  • 0

In my VIew ive got 3 checkboxes, i want to validate them that way :

if one checkbox is checked other 2 is disabled, if checked checkbox is unchecked, other 2 checkboes is enabled again.

Controller

  public ActionResult SolarPart()
    {
        var model = new SolarParentViewModel();
        var list = new List<URLTimeLimitViewModel>();
        list.Add(new URLTimeLimitViewModel { Name = "14 dage", IsChecked = false, Id = 1 });
        list.Add(new URLTimeLimitViewModel { Name = "1 Måned", IsChecked = false, Id = 2 });
        list.Add(new URLTimeLimitViewModel { Name = "2 Måneder", IsChecked = false, Id = 3 });
        model.TimeLimit = list;
        return View(model);
    }

View

@for (var i = 0; i < Model.TimeLimit.Count; i++)
{
  <div class="editor-label">
    @Html.LabelFor(c=>Model.TimeLimit[i].Name, Model.TimeLimit[i].Name)
      @Html.HiddenFor(c=>Model.TimeLimit[i].Id) 
      @Html.CheckBoxFor(c=>Model.TimeLimit[i].IsChecked)
  </div>
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:25:47+00:00Added an answer on May 29, 2026 at 1:25 pm

    If the values are mutually exclusive you might consider using radio buttons instead of checkboxes. They seem more adapted to your scenario. If for some very weird reason you still want to use checkboxes which are mutually exclusives you could use javascript and subscribe to the change event of each of them and based on the value toggle the other 2 checkboxes. And for validating this model on the server you could write a custom validation attribute which could either be applied to the TimeLimit property on your view model:

    public class MaximumOneTimeLimitCanBeCheckedAttribute : ValidationAttribute
    {
        public override bool IsValid(object value)
        {
            var list = value as IEnumerable<URLTimeLimitViewModel>;
            if (list == null)
            {
                return true;
            }
            return list.Where(x => x.IsChecked).Count() < 2;
        }
    }
    

    and then:

    public class SolarParentViewModel
    {
        [MaximumOneTimeLimitCanBeChecked]
        public IList<URLTimeLimitViewModel> TimeLimit { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a custom control ive created that is instanced in my view, in
I want to limit the number of checked checkboxes in my listview. I've got
Ive got a button in a UICell. I want a list(a table view like
Ive got a view helper in library/my/view/helper/gravatar and so in any view I can
Ive got a url: http://dev.local/foodies/view?id=bluedaniel and ive got in my bootstrap: protected function _initRoute()
I've got a view in my app that does pretty much everything, and I
I've got a view function that has to decide which form to use depending
I've got a tree view that can be anywhere from 1 level deep to
I've got a detail view that consists of a table view with a few
I've got a grid view. I want it to say you have nothing to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.