[RESOLVED]in view : How to detect which of two checkbox selected in view

hello

How to detect which of two checkboxes selected in view?

Do you want to do this when the form is posted to the server or on the client? How are you generating your checkboxes?

hello!

on the client

there are two checkboxes and one button in the view (in client)

when button clicked, the value of selected checkbox sent to controller. (to server)

Hi,

There are two ways.

1. You can use jquery to find out the checkbox value and make ajax call with values.

2. You can bind the model to the view checkboxes and when you make the server call, the updated model values will be available in the controller.

public class CheckBoxModel
{
            public int Id{ get; set; }
    public bool IsSelected { get; set;  }
}

@Html.CheckBoxFor(m => m.IsSelected)

You can get the value on the client using jQuery:

var selectedVal = $('input[type="checkbox"]:checked').val();

So thanks for all . . .

Leave a Reply