Syncfusion MVC Datagrid - 如何在行中显示按钮



我有一个Syncfusion MVC Datagrid,我需要在每一行中显示一个自定义按钮才能执行一些操作。"员工详细信息"列是从其网站剪切和粘贴的:https://help.syncfusion.com/aspnetmvc/grid/columns?cs-save-lang=1&cs-lang=razor

VS 错误:

无法将 lambda 表达式转换为类型"对象",因为它不是 委托类型

使按钮显示的正确语法是什么?

此外,我需要正确的 jscript/控制器代码来回调控制器并取回 ID 或所选项目。

@Html.EJS().Grid("DataGrid").DataSource(ds => ds.Json(ViewBag.datasource).UpdateUrl("/Management/Update").InsertUrl("/Management/Insert").RemoveUrl("/Management/Remove").Adaptor("RemoteSaveAdaptor")).AllowTextWrap().Columns(col =>
{
col.Field("Id").IsPrimaryKey(true).Visible(false).Add();
col.Field("ResourceGroup").HeaderText("Source VM Resource Group").Add();
col.Field("VMName").HeaderText("Source VM Name").Add();
col.Field("ImageDate").HeaderText("Image Capture Start Date").Width(150).Format("yyyy-MMM-dd hh:mm").HeaderTextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).EditType("datetimepickeredit").Edit(new { @params = new { min = System.DateTime.UtcNow, showclearbutton = true } }).Add();
col.Field("ImageRecurrance").HeaderText("Image Recurrence (days)").EditType("numericedit").Edit(new { @params = new { min = 0, step = 10, decimals = 0, strictmode = true } }).Width(100).Add();
col.Field("ImageVersion").HeaderText("Image Version").Add();
col.HeaderText("Employee Details").Commands(command =>
{
command.Type("detail")
.ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties()
{
Text = "Details",
Width = "100px",
Click = "onClick"
}).Add();
})                
.TextAlign(TextAlign.Center)
.Width(150)
.Add();
}).ActionFailure("OnActionFailure").AllowTextWrap(true).TextWrapSettings(text => { text.WrapMode(Syncfusion.EJ2.Grids.WrapMode.Header); }).AllowPaging().FilterSettings(filter => { filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu); }).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).ShowDeleteConfirmDialog(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(toolbarItems).TextWrapSettings(text => { text.WrapMode(Syncfusion.EJ2.Grids.WrapMode.Header); }).Render()

该按钮很简单,具有以下列模板:

  • 管理= 控制器
  • 选择= 操作
  • ${Id}= 要传递给查询字符串的值

<a href='/Management/Select?Id=${Id}'>
<button class='e-control e-btn e-lib' id='button' type='button'>Related</button>
</a>

网格定义

@{int buttonWidth = 160; } 
@Html.EJS().Grid("DataGrid").DataSource(ds => ds.Json(ViewBag.datasource).UpdateUrl("/Management/Update").InsertUrl("/Management/Insert").RemoveUrl("/Management/Remove").Adaptor("RemoteSaveAdaptor")).AllowTextWrap().Columns(col =>
{
col.Field("Id").IsPrimaryKey(true).Visible(false).Add();
col.Field("RG").HeaderText("RG").Width(@colWidth).Add();
col.Template("<a href='/Management/Select?Id=${Id}'><button class='e-control e-btn e-lib' id='button' type='button'>Related</button></a>").AllowEditing(false).Width(@buttonWidth).Add();
}).ActionFailure("OnActionFailure").AllowTextWrap(true).TextWrapSettings(text => { text.WrapMode(Syncfusion.EJ2.Grids.WrapMode.Header); }).AllowPaging().FilterSettings(filter => { filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu); }).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).ShowDeleteConfirmDialog(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(toolbarItems).TextWrapSettings(text => { text.WrapMode(Syncfusion.EJ2.Grids.WrapMode.Header); }).Render()

控制器

public class ManagementController : Controller
{
...
public ActionResult Select(object newItem)
{
var id = System.Convert.ToInt32(this.Request.QueryString["Id"]);

最新更新