Click here to Skip to main content
13,095,921 members (53,857 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hii to everyone,
for the last 2weeks i started learning MVC3,i started preparing a registration page using MVC3 Razor view,here user need to select area of intrest, for this i placed 4 checkboxes.My requirement is i need to restrict the user to select only one checkbox at any point of time, how can i achieve this....also try to tell me the possible events associated with checkbox in mvc3 Razor

Posted 25-Apr-13 23:59pm
patel_vijay 26-Apr-13 6:05am
IF you want user to restrict on only one selection then why not to use RadioButton instead of Checkbox control.
Ram7 from Hyderabad 26-Apr-13 6:19am
Dear Vijay,thanks for ur responce my requirement is with checkbox only,i will try with ur code,thanks once again for ur responce......
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

And still if you want to go with checkboxes then checkout sample on jsFiddle[^]

Use below function to restrict user on single selection

<input type="checkbox" id="chk1" class="chk" name="chk1" /> checkbox 1
<input type="checkbox" id="chk2" class="chk" name="chk2" /> checkbox 2
<input type="checkbox" id="chk3" class="chk" name="chk3" /> checkbox 3
<input type="checkbox" id="chk4" class="chk" name="chk4" /> checkbox 4

        if($('input.chk').length > 1){
Zoltán Zörgő 26-Apr-13 6:49am
It is working but still not a good answer. Why? Because it does not fit into the practices of ASP.NET MVCx (like unobstructive validation), but first of all, because it is a "client side only" solution. What if user disables JavaScript, checks all, and posts the form.
patel_vijay 26-Apr-13 7:05am
True, Server side validation is required if data is critical. There are possibilities that user has disabled JavaScript and it is not handled in application then user should be redirect to some page and needs to be notified to enable it.
And don't you think so if JavaScript is disable then most of the functionality of application stop working? :)
Zoltán Zörgő 26-Apr-13 13:11pm
The one disabling JavaScript is either developer, hacker, or in high security environment. You don't have to disable JS for ever, you can disable just to bypass such validation steps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100