【发布时间】:2014-10-31 16:50:56
【问题描述】:
我需要向剑道网格工具栏添加按钮,单击该按钮将显示弹出窗口。我还需要将此网格包装在一个助手中,该助手将使用此按钮返回网格。问题是我需要将参数传递给显示弹出窗口(具体为网格类型)的操作,但我不能使用 *.cs 文件中定义的这个帮助程序的 razor 语法,而且我找不到方法用普通的 c# 来做。我能以某种方式做到这一点吗?代码如下:
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")))
【问题讨论】:
-
你能不能把
@using Test.WebUI.Helpers放到你想使用这个助手的视图中? -
@BenRobinson,抱歉,这有什么帮助?
标签: c# asp.net-mvc razor telerik kendo-grid