【问题标题】:Kendo UI Grid Pass parameter to action from cell dataKendo UI Grid Pass 参数到单元格数据的操作
【发布时间】:2016-12-31 19:29:56
【问题描述】:

我试图弄清楚如何从我选择的行的单元格中获取数据。我需要它作为我的URL.Action 中的参数。有没有办法做到这一点?如果是这样,怎么做?

下面是代码。

@(Html.Kendo().Grid(Model.dailyLogEventList)
        .Name("dailyLogGrid")
        .HtmlAttributes(new { style = "height: 360px" })
        .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(8)
        .Read(read => read.Action("DailyLogList_Read", "DailyLog"))
        )
.Columns(columns =>
{
    columns.Bound(x => x.IsEventRequired)
        .ClientTemplate("<a href='" + Url.Action("index", "IncidentReport", new { area = "DailyLog"   }) 
        + "'>" + "#= IsEventRequired ? '<img src=\"/Images/icon_edit.gif\" />' : '' #" + "</a>")
        .Width(25)
        .Title("")
        .Filterable(false);
    columns.Bound(x => x.LogId).Width(25).Title("Id");
    columns.Bound(x => x.StartDate).Title("Started").Format("{0:MM/dd/yyyy HH:mm}").Width(60).Sortable(true);
    columns.Bound(x => x.EventDescription).Title("Event").Width(120).Filterable(filterable => filterable.UI("eventDescFilter"));
    columns.Bound(x => x.Comments).Title("Comments").Width(200);
    columns.Bound(x => x.RespondingOfficers).Title("Officer(s)").Width(190);
    columns.Command(command => command.Custom("Edit").Click("loadDataForEdit")).Width(20)
        .HtmlAttributes(new { style = "text-decoration:none; text-align:right;" })
        ;

})
    .Pageable()
    .Selectable(s => s.Mode(GridSelectionMode.Single))
    .Filterable()

        )

【问题讨论】:

    标签: kendo-ui url.action


    【解决方案1】:

    您可以通过以下 JQuery 代码访问选定的单元格信息。

    $('#dailyLogGrid).click(function () {
            var gview = $(this).data("kendoGrid");
            var selectedItem = gview.dataItem(gview.select());
            var cellValue= selectedItem.PropertyName;
            $("#HiddenField").val(cellValue); //Store value in hidden field
        })
    
      @Html.Hidden("HiddenField")
    

    查看以下帖子以获取 URL.Action 的值,它需要使用 FormCollection。

    reading hidden field value in action?

    【讨论】:

    • 谢谢。这是比我想出的更好的解决方案。
    猜你喜欢
    • 1970-01-01
    • 2012-12-10
    • 2019-03-03
    • 2014-04-20
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 2013-07-26
    • 1970-01-01
    相关资源
    最近更新 更多