2017-09-05 15 views
0

これは私のコントローラです。ここでは、2つのテーブルからデータを取得しています。一方は親テーブルで、もう1つは子テーブルです。剣道のリストボックスにクライアントテンプレートを使用する方法

public JsonResult ReadAllFeatures() 
      { 
       var fetaures = _featuresService.GetFeatures(0); 
       //HaBo: I recommend not doing this here, right way to do it is using client template on the client side 
       foreach (var fetaure in fetaures) 
       { 
        fetaure.Name = $"{fetaure.Module.Name} >> {fetaure.Name}"; 
       } 
       return Json(fetaures, JsonRequestBehavior.AllowGet); 
      } 

私はこのように私のデータを表示したい:

Image

が、私はfetaure.Name = $"{fetaure.Module.Name} >> {fetaure.Name}";などの利用制御コードを望んでいません。私は剣道のリストボックスのクライアントテンプレートを使用する必要がありますので、簡単になります。

そして、これは私のview.cshtmlコード剣道MVCでリストボックスのクライアント寺を使用する方法

@(Html.Kendo().Grid<OfficeGx.Domain.Model.SubscriptionTier>() 
     .Name("SubscriptionGrid") 
     .Columns(columns => 
     { 
      columns.Bound(c => c.Id); 
      columns.Bound(c => c.Name); 
      columns.Command(command => 
      { 
       command.Edit().Text(" ").UpdateText("Save"); 
       command.Destroy().Text(" "); 
      }); 
     }) 
     .ClientDetailTemplateId("SubscriptionTierGriditem") 
     .Sortable() 
     .ToolBar(toolbar => 
     { 
      toolbar.Create().Text("Add New SubscriptionTier"); 
     }) 
     .Editable(editable => editable.Mode(GridEditMode.InLine) 
    ) 
     .Pageable(pageable => pageable 
      .Refresh(true) 
      .PageSizes(true) 
      .ButtonCount(5)) 
     .Resizable(resize => resize.Columns(true)) 
     .Reorderable(reorder => reorder.Columns(true)) 
     .DataSource(dataSource => dataSource 
      .Ajax() 
      .Batch(true) 
      .Model(model => 
      { 
       model.Id(x => x.Id); 
       model.Field(c => c.Id).Editable(false); 
       model.Field(c => c.Name).Editable(true); 
      }) 
      .Read(read => read.Action("ReadTiers", "Config")) 
      .Create(update => update.Action("AddTier", "Config")) 
      .Update(update => update.Action("UpdateTier", "Config")) 
      .Destroy(update => update.Action("DeleteTier", "Config")) 
      .PageSize(20) 
    )) 
<script id="SubscriptionTierGriditem" type="text/kendo-tmpl"> 
    @(Html.Kendo().Grid<OfficeGx.Domain.Model.Subscription>() 
      .Name("SubscriptionTierGriditem_#=Id#") 
      .Columns(columns => 
      { 
       //columns.Bound(c => c.Id); 
       columns.Bound(c => c.Name); 
       //columns.Bound(c => c.Description); 
       columns.Bound(c => c.Price); 
       columns.Bound(c => c.MaxUserInvites).Title("Users"); 
       //columns.Bound(c => c.TierId); 
       columns.Bound(c => c.CallForQuote); 
       columns.Bound(c => c.DiscountTerm).Title("Disc. Term"); 
       columns.Bound(c => c.TearmWiseDiscount).Title("Discount"); 
       columns.Bound(c => c.IsActive); 
       columns.Command(command => 
       { 
        command.Edit().Text(" ").UpdateText("Save"); 
        command.Destroy().Text(" "); 
       }); 
      }) 
      .ClientDetailTemplateId("Feature") 
      .Sortable() 
      .ToolBar(toolbar => 
      { 
       toolbar.Create().Text("Add New Subscription"); 
      }) 
      .Pageable(pageable => pageable 
       .Refresh(true) 
       .PageSizes(true) 
       .ButtonCount(5)) 
      .Resizable(resize => resize.Columns(true)) 
      .Reorderable(reorder => reorder.Columns(true)) 
      .DataSource(dataSource => dataSource 
       .Ajax() 
       .Batch(true) 
       .Model(model => 
       { 
        model.Id(x => x.Id); 
        model.Field(c => c.Id).Editable(false); 
        model.Field(x => x.Name).Editable(true); 
        model.Field(x => x.Description).Editable(true); 
        model.Field(x => x.IsActive).Editable(true); 
        model.Field(x => x.Price).Editable(true); 
        model.Field(x => x.MaxUserInvites).Editable(true); 
        model.Field(x => x.TierId).Editable(false); 
        model.Field(x => x.CallForQuote).Editable(true); 
        model.Field(x => x.DiscountTerm).Editable(true); 
        model.Field(x => x.TearmWiseDiscount).Editable(true); 
       }) 
       .Read(read => read.Action("ReadSubscriptions", "Config", new { TierId = "#=Id#" })) 
       .Create(update => update.Action("AddSubsctiption", "Config", new { TierId = "#=Id#" })) 
       .Update(update => update.Action("UpdateSubscription", "Config", new { TierId = "#=Id#" })) 
       .Destroy(update => update.Action("DeleteSubscription", "Config")) 
       .PageSize(20) 
      ).ToClientTemplate() 
    ) 
</script> 
<script id="Feature" type="text/kendo-tmpl"> 
    <div id="access-section"> 
     <label for="AllRoles" id="allRoles">Available Features</label> 
     <label for="selectedRoles">Assigned Features</label> 
     <br /> 
     @(Html.Kendo().ListBox() 
          .Name("module") 
          .Toolbar(toolbar => 
          { 
           toolbar.Position(Kendo.Mvc.UI.Fluent.ListBoxToolbarPosition.Right); 
           toolbar.Tools(tools => tools 
            .TransferAllFrom() 
            .TransferFrom() 
            .TransferTo() 
            .TransferAllTo() 
            .Remove()); 
          }) 
        //  .Events(events => events 
        //.Add("onRemove") 
        //.Remove("onAdd") 
        .ConnectWith("selected") 
        .DataSource(x => x.Read(r => r.Action("ReadAllFeatures", "Config",0))) 
        .DataTextField("Name").DataValueField("Id") 
        .DropSources("selected") 
        .BindTo(new OfficeGx.Domain.Model.Module().Name) 
        .ToClientTemplate() 

     ) 
     @(Html.Kendo().ListBox() 
      .Name("selected") 
      .DataTextField("Name") 
      .ToClientTemplate() 
    ) 
    </div> 
</script> 
<script> 
    function onRemove(e) { 
     postToDb(e, false); 
    } 
    function onAdd(e) { 
     postToDb(e, true); 
    } 
</script> 
<script id="item-template" type="text/x-kendo-template"> 
    @*<span class="k-state-default" style="background-image: url('../content/web/Customers/#:data.CustomerID#.jpg')"></span>*@ 
    <span class="k-state-default"><b>#=data fetaure.Module.Name=#</b></p>#:==#</p></span> 
</script> 

あるので、私は私のデータの正しい方法を表示することができますか?あなたは、両方のリストボックスに次の行(左側と右側)

.TemplateId("feature-item-template") 

を追加する必要が

+0

これは、キノリストボックスでclienttemplatesを使用する方法です。https://demos.telerik.com/aspnet-mvc/listbox/templates – HaBo

答えて

0

は、あなたのテンプレートは、この

<script id="feature-item-template" type="text/x-kendo-template"> 
<span class="k-state-default"><h3>#: data.Name # </h3><p>#: data.Module.Name #</p></span> 
</script> 

剣道のドキュメントがあれば、非常に詳細であるように見えますあなたは読書に時間を費やすことを気に、すぐにそれを学ぶことができます。

+0

回答ありがとうございます。ただし、リストボックスのtemplateIdを直接使用すると問題が発生します。しかし、親グリッドのClientDetailedTemplateで同じものを使用すると、リストボックスのtemplateidが無効なテンプレートとして失敗しています。ホンダ剣道はこの問題のためにキツネを思いつくことができる – Dinesh

関連する問題