I have some jQuery I'm using to "do stuff" depending on the value of a selected radio button. It works perfectly fine and as expected...until I submit the page and POST back to itself. After a POST, the value of 'this' within the function is always the first radio button - "filterByCategory1". I think this has something to do with MVCs abusing of radio button id's (same id for multiple buttons), but that's an uneducated guess.
the jQuery:
$('input[id^="filterBy"]').change(function (e) {
if ($(this).val() == 'filterByCategory1') {
// do stuff
} else if ($(this).val() == 'filterByCategory2') {
// do other stuff
}
});
// Just to make "do stuff" happen on initial page load
$('#filterBy').change();
The razor bit
@Html.RadioButtonFor(x => x.filterBy, "filterByCategory1", new { @checked = "checked" }) One <br />
@Html.RadioButtonFor(x => x.filterBy, "filterByCategory2") Two