2012-10-16 26 views
0

我在特定視圖中添加了MvcContrib網格。在網格中,連同列數據,我也有一個單選按鈕列。我正在嘗試獲取選定的單選按鈕單擊事件,但未按預期發生。我不知道實施有什麼問題。你們可以看看,並給出一些建議或代碼片段來解決這個問題。在MVCContrib Grid中使用jquery選擇Radiobutton MVC3

<%= 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代碼來選擇單選按鈕點擊:

$("input[type='radio']").click(function() { 
       alert("kaustubh"); 
      }); 

也試過以下一個太:

$("input[name='defaultRastaurant']").change(function() { 
      alert("kaustubh");    
          }); 

回答

1

看起來像它的一個事件委派問題。當事件處理程序相關聯的給它的元素不存在於DOM ..

嘗試此

$("body").on("click"," input[type='radio']" ,function() { 
     alert("kaustubh"); 
}); 

主體可以由任何非靜態父其中單選按鈕存在替換..