views:

46

answers:

3

Hello friends using this code I am to get only checked id

the beginForm

I am perfectly getting all my chekced id's to the controler but I need to get both checked as well as uncheked ids' using above code?

thanks

A: 

try this jquery $("#PricingEditExceptions :not(:checked)")

griegs
how to incorporate this code with above code so that in one click i can get these ids?
kumar
A: 

i get it now (thanks funka):

something like:

$("#PricingEditExceptions input[type=checkbox").each(function() {
   $(this).prepend('<input type="hidden" name="' + $(this).attr('name') + '" value="0" />');
});

will force 0 for every item.. if the check box is fired, it's the last element which is what's sent to the server (overrides the hidden form element)

Basically, make it look like

<input type="hidden" name="exc-1" value="0" />
<input type="checkbox" name="exc-1" value="1" />

<input type="hidden" name="exc-2" value="0" />
<input type="checkbox" name="exc-2" value="1" />

and now you just check for 0 or 1 if it was checked. Edit: maybe i'm not being clear? if exc-1 is checked and exc-2 isn't, then you'll get

exc-1 = 1
exc-2 = 0 

checked and unchecked, server-side.. ya?

Dan Heberden
no on server side i need to have the chekced users also.. so that i can update checked users as well as unchecked user...
kumar
yeah, funka cleared it up - changed my answer
Dan Heberden
i need both cheked and uncheked users..thanks for your time
kumar
exactly - hence my answer?
Dan Heberden
Thanks let me try with that..i will update you with in two min..
kumar
A: 

Your question seems to start off looking like a jQuery question, but is this perhaps an ASP.NET MVC question?

Unchecked checkboxes are not sent to the server. Only checked checkboxes will send a value.

Depending on how you are drawing the checkboxes, ASP.NET MVC may include (not sure of the real name for this) what I call a "hidden partner" field with your checkboxes which the model-binder can look at to decide which (boolean) values are true, and which are false.

If you are drawing your checkboxes manually through HTML, you will need to find another way to do this. Could you please elaborate on exactly where you are trying to access these fields?

Funka
Also, beware using CSS classes and IDs that start with a number. These identifiers should ideally start with a letter.
Funka
in my requirement, i need to do some updates for chekced users and other updates for uncheked users.. so my code will work for cheked users i am getting perfectly to the server side.. i need to know uncheked user on server side too..so both i need to find out.. checked and uncheked..
kumar
shouldn't the controller already know which users were just shown on the page?
Funka
no the controler doesnot know about that.. its just takes the id's from the view which we are passing on beginform.that;s what my above code which i wrote..
kumar
ah, so is your view being constructed by hand? Is it getting populated from some other data source?
Funka