2014-10-31 15 views
0

我需要将按钮添加到kendo网格工具栏,该按钮将在点击时显示弹出窗口。我还需要将这个网格包裹在一个帮助器中,该帮助器将使用此按钮返回网格。该proplem是我需要传递参数的行动,它显示弹出窗口(网格类型是具体的),但我不能使用剃刀语法作为这个助手在* .cs文件中定义,我找不到方法通过常规的c#来完成。我能以某种方式做到这一点吗?下面是代码:将参数传递给使用纯c的Kendo网格工具栏中的动作#

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Security.Policy; 
using System.Web; 
using System.Web.Mvc; 
using Kendo.Mvc.UI; 

namespace Test.WebUI.Helpers 
{ 

public static class ExtendedGridHelper 
{ 

    public static Kendo.Mvc.UI.Fluent.GridBuilder<T> ExtendedGrid<T>(this HtmlHelper helper, string name, Tuple<string, string> dataAccessing) 
     where T : class 
    { 
     return helper.Kendo().Grid<T>() 
      .Name(name) 
      //.DataSource(src => src.Ajax().Read(read => read.Action("GetInstances", "ExtendedGrid"))) 
      .DataSource(src => src.Ajax().Read(dataAccessing.Item1, dataAccessing.Item2)) 
      .Sortable() 
      .Pageable(it => it.PageSizes(true)) 
      .Groupable() 
      .Filterable() 
      .Reorderable(it => it.Columns(true)) 
      .Scrollable(it => it.Virtual(true)) 
      .Selectable(selectable => selectable.Mode(GridSelectionMode.Single)) 
      .Columns(columns => 
      { 
       foreach (var property in typeof (T).GetProperties().OrderBy(it => it.Name)) 
       { 
        columns.Bound(property.Name).Width(150); 
       } 
      } 
        ) 


      .ToolBar(toolbar => 
      { 
       toolbar.Custom().Action("ViewPopup", "ExtendedGrid").Text("Settings").HtmlAttributes(new {@class = "modal-link btn btn-success"}); 
      //This way it works, but I nered to pass parameter.  
      } 

      ); 
    } 




} 
} 

下面是使用的例子:

@(Html.ExtendedGrid<ololo>("Grid1", new Tuple<string, string>("GetInstances", "ExtendedGrid"))) 
+0

难道你们就不能只是把'@using Test.WebUI.Helpers'到您想要使用这个助手的意见? – 2014-10-31 17:08:36

+0

@BenRobinson,对不起,但它会有帮助吗? – KorsaR 2014-10-31 17:26:52

回答

0

我的数字这个出来,也许这对某个人来说是有用的。我只是说这个资源:

<div style="width: 100%;"> 
<a onclick = "show_settings()" href='#' class = "modal-link btn btn-success">Settings</a> 
</div> 
<script type="text/javascript"> 
function show_settings(){ 
     $.post("/ExtendedGrid/ViewPopup/", {objectType: "~T~", userID: "~userID~", listOfColumns: "~ListOfColumns~"}, 
               function (result) { $('#modal-container').html(result); 
               }); 
     } 
</script> 

然后:

var popupTemplate = Properties.Resources.ToolbarTemplate 
      .Replace("~T~", typeof (T).ToString()) 
      .Replace("~userID~", userID) 
      .Replace("~GridName~", name) 
      .Replace("~ExportAction~", String.Format("/{0}/{1}", dataAccessing.Item2, dataAccessing.Item1)); 
.ToolBar(toolbar => toolbar.Template(popupTemplate)); 
0

为SEND参数与剑道的DataSource使用此代码的

.DataSource(dataSource => dataSource.Ajax().Read(read => read.Action("Products_Read", "Grid").Data("additionalInfo")) 

,并在javascript让您的JSON数据

function additionalInfo() { 
return { 
    AdditionalParam : "test" 
} 
+0

我可以在哪里放JS?正如我上面提到的,我有cs文件。这是主要问题。 – KorsaR 2014-10-31 18:19:55