I have added a MvcContrib grid in a particular view. In grid, along with the column data, I also have a radiobutton column. I am trying to get selected radiobutton click event but it's not happening as expected. I don't know what's wrong with the implementation. Can you guys have a look and give some suggestion or code snippet to resolve this issue.
<%= Html.Grid(Model.Items)
.Columns(column =>
{
column.For(x => x.Name)
.Named(Html.OrderBy(null, "DisplayRestaurantsList", "Group", ViewContext.RouteData.Values, "sortBy", "sortDir", true, Model.SortDirection, Model.SortBy, "restaurantname", "Restaurant"));
column.For(x => x.Contact.GetDisplayName())
.Named(Html.OrderBy(null, "DisplayRestaurantsList", "Restaurant", ViewContext.RouteData.Values, "sortBy", "sortDir", true, Model.SortDirection, Model.SortBy, "administrator", "Administrator"));
column.For(x => Html.ActionLink("Remove", "RemoveRestaurant", "Group", new { id = x.ID, GroupID=x.Group.ID }, null))
.DoNotEncode();
column.For(x => Html.RadioButton("defaultRastaurant",x.ID,(!x.Group.ID.Value.ToString().IsEmptyOrNull() && x.ID==x.Group.DefaultRestaurantID) ? true:false)).Named("default").DoNotEncode();
})
.Attributes(@class => "table-1 gapmb40")
.Empty("There are no restaurants that match your criteria.")
.RowStart(row => string.Format("<tr{0}>", row.IsAlternate ? "style=\"background-color:#CCDDCC\"" : ""))
%>
jQuery code to select the radio button click:
$("input[type='radio']").click(function () {
alert("kaustubh");
});
Also tried following one too:
$("input[name='defaultRastaurant']").change(function () {
alert("kaustubh");
});
Looks like its a event delegation issue. The element is not present in the DOM when the event handler is associated to it..
Try this
The body can be replaced by any non static parent in which the radiobuttons are present..