ASP.NET MVC ClientSide事件

时间:2016-06-14 22:34:14

标签: asp.net-mvc devexpress

我正在尝试学习MVC,来自.NET背景。我有一个带有devexpress gridview控件的索引页面,我正在尝试添加一个focusedrowchanges事件。我的索引页面仅包含以下内容

<main style="width:100%">
    @Html.Action("GridViewPartial")
</main>

我的Gridviewpartial如下

@{
    var grid = Html.DevExpress().GridView(settings =>
    {
    settings.Name = "GridView";
    settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartial" };

    settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Home", Action = "GridViewPartialAddNew" };
    settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Home", Action = "GridViewPartialUpdate" };
    settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Home", Action = "GridViewPartialDelete" };
    settings.ClientSideEvents.FocusedRowChanged = "OnRowSelect";
    //settings.ClientSideEvents.FocusedRowChanged = "function(s, e) {alert('The button has been clicked');}";


    settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;
    settings.SettingsBehavior.ConfirmDelete = true;

    settings.CommandColumn.Visible = false;
    settings.CommandColumn.ShowNewButton = false;
    settings.CommandColumn.ShowDeleteButton = false;
    settings.CommandColumn.ShowEditButton = false;

    settings.KeyFieldName = "id";

    settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

    settings.SettingsAdaptivity.AdaptivityMode = GridViewAdaptivityMode.Off;
    settings.SettingsAdaptivity.AdaptiveColumnPosition = GridViewAdaptiveColumnPosition.Left;
    settings.SettingsAdaptivity.AdaptiveDetailColumnCount = 1;
    settings.SettingsAdaptivity.AllowOnlyOneAdaptiveDetailExpanded = false;
    settings.SettingsAdaptivity.HideDataCellsAtWindowInnerWidth = 0;

    settings.Columns.Add("reference");
    settings.Columns.Add("name");
    settings.Columns.Add("description");

});
if (ViewData["EditError"] != null)
{
    grid.SetEditErrorText((string)ViewData["EditError"]);
}
}
@grid.Bind(Model).GetHtml()

正如您所看到的,我添加了一个focusedrowchanges事件并尝试了两种不同的使用方式。我目前正试图让它使用javascript函数。

<script type="text/javascript">
    function OnRowSelect(s, e) {
        alert('test');
        }
</script>

当我在网格上更改聚焦行时似乎没有进入该功能,我不知道为什么会这样。我也试过在函数中设置一个断点,这是永远不会被击中的。有人可以解释我应该如何正确地做到这一点吗?

1 个答案:

答案 0 :(得分:1)

你的方法都可行(在我自己的一个项目上试过)。 您只是缺少一个设置:// GET: api/Courses/5 [ResponseType(typeof(Course))] public async Task<IHttpActionResult> GetCourse(int id) { Course course = await _db.Courses.FindAsync(id); if (course == null) { return NotFound(); } return Ok(course); }

DevExpress demo也证明了相同的内容。