2011-04-02 82 views
0

我在嘗試使用asp.net mvc telerik網格提供的客戶端時遇到嚴重問題。 以下是兩種不同的場景: 當我將下面的腳本放在視圖或局部視圖中時,它可以正常工作;Telerik MVC Extension - 在Tabstrip中加載的網格不支持clientEvents

<%= Html.Telerik().Grid<Plan>() 
      .Name("Grid") 
      .DataKeys(keys => keys.Add(p => p.StaffId)) 
      .ToolBar(commands => { commands.SubmitChanges(); 
            commands.Position(GridToolBarPosition.Bottom); 
      }).PrefixUrlParameters(false) 

      .DataBinding(dataBinding => 
       dataBinding.Ajax() 
         .Select("_SelectBatchEmployees", "Employee") 
        .Update("_SaveBatchEmployees", "Employee") 
      ) 
      .Columns(columns => 
      { 
       columns.Bound(p => p.FullName).Width(320).ReadOnly(true); 
       columns.Bound(p => p.Title).Width(220).ReadOnly(true); 
       columns.Bound(p => p.PerformanceRating).Title("Perf. Rating").Format("{0:n}").Width(80); 
       columns.Bound(p => p.RecommendedIncreaseAmountFrom).Width(80); 

      }) 
      .ClientEvents(events => 
        events.OnDataBinding("Grid_onDataBinding").OnError("Grid_onError").OnEdit("onEdit").OnDataBound("onDataBound")) 
      .Editable(editing => editing.Mode(GridEditMode.InCell)) 
      .Pageable(page => page.PageSize(40)) 
      .Scrollable() 
      .Sortable() 
      .Footer(true) 

      %> 


    <script type="text/javascript"> 
     function Grid_onError(args) { 
      if (args.textStatus == "modelstateerror" && args.modelState) { 
       var message = "Errors:\n"; 
       $.each(args.modelState, function (key, value) { 
        if ('errors' in value) { 
         $.each(value.errors, function() { 
          message += this + "\n"; 
         }); 
        } 
       }); 
       args.preventDefault(); 
       alert(message); 
      } 
     } 
     function onDataBound(e) { 
      //alert(e.dataItem); 
     } 

     function onEdit(e) { 
      var dataItem = e.dataItem; 
      var mode = e.mode; 
      var form = e.form; 
      var priceTextBox = $(form).find('#Grade'); 
      dataItem.RecommendedIncreaseAmountFrom = 10 * 5; 

      e.preventDefault(); 


     } 

     function Grid_onDataBinding(e) { 
      var grid = $(this).data('tGrid'); 
      if (grid.hasChanges()) { 
       if (!confirm('You are going to lose any unsaved changes. Are you sure?')) { 
        e.preventDefault(); 
       } 
      } 
     } 

     </script> 

但是,當我部分加載查看通過tabstrip按需加載它不起作用。當我刪除客戶端部分時,它開始工作?我不知道是什麼原因,但我需要工作,請幫助我,這裏是我的代碼:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Edit.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> 

    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
     Index 
    </asp:Content> 

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
    <%= 
       Html.Telerik().TabStrip() 
        .Name("planingTabs").HtmlAttributes(new {style = "overfloat:auto"}) 
        .Items(parent => parent.Add() //.HtmlAttributes(new {style = "overfloat:auto"}) 
             .Text("Test") 
             .LoadContentFrom("PlanGrid", "Employee").Selected(true)) 

      %> 

    </asp:Content> 

下面是控制器代碼:

public ActionResult Index() 
      { 
       return View(); 
      } 

      public ActionResult PlanGrid() 
      { 
       return PartialView(); 
      } 

      [GridAction] 
      public ActionResult _SelectBatchEmployees() 
      { 
          return View(new GridModel { Data = _employeeRepository.GetAll()}); 
      } 
      [AcceptVerbs(HttpVerbs.Post)] 
      [CultureAwareAction] 
      [GridAction] 
      public ActionResult _SaveBatchEmployees([Bind(Prefix = 
       "inserted")]IEnumerable<Plan> insertedProducts, 
       [Bind(Prefix = "updated")]IEnumerable<Plan> updatedProducts, 
       [Bind(Prefix = "deleted")]IEnumerable<Plan> deletedProducts) 
      { 

       //if (insertedProducts != null) 
       //{ 
       // foreach (var product in insertedProducts) 
       // { 
       //  SessionProductRepository.Insert(product); 
       // } 
       //} 
       if (updatedProducts != null) 
       { 
        foreach (var employee in updatedProducts) 
        { 
         var target = _employeeRepository.One(p => p.StaffId == employee.StaffId); 
         if (target != null) 
         { 
          //target.ProductName = product.ProductName; 
          //target.UnitPrice = product.UnitPrice; 
          //target.UnitsInStock = product.UnitsInStock; 
          //target.LastSupply = product.LastSupply; 
          //target.Discontinued = product.Discontinued; 


          _employeeRespository.Save(); 
         } 
        } 
       } 
       //if (deletedProducts != null) 
       //{ 
       // foreach (var product in deletedProducts) 
       // { 
       //  SessionProductRepository.Delete(product); 
       // } 
       //} 
       return View(new GridModel { Data = _employeeRespository.GetAll() }); 
      } 

回答