1

这是从索引中调用的局部视图。在模型中,JobStatusSortOrder 设置为可为空的双精度。在这里,如果用户在内联编辑期间没有输入任何值,我如何将值默认设置为 null。我曾尝试寻找默认文本等选项,但找不到任何可以帮助我的选项。有人可以帮我吗?谢谢!

@model MyProject.Web.ViewModels.ProjectStatusListViewModel

@using MyProject.Data.Models;
@using System.Web.UI.WebControls;
@using DevExpress.Web.Mvc.UI;
@using DevExpress.Web.ASPxEditors;
@using DevExpress.Web.Mvc;
@using DevExpress.Web.ASPxGridView;

@{
Html.EnableClientValidation(true);

var grid = Html.DevExpress().GridView(
    settings =>
    {
        settings.Name = "gvProjectStatus";
        settings.KeyFieldName = "JobStatusID";
        settings.Width = Unit.Pixel(1080);
        settings.CallbackRouteValues = new { Controller = "Maintenance", Action = "ProjectStatusMasterPartial" };
        settings.ClientSideEvents.BeginCallback = "function(s,e){e.customArgs['id'] = '" + ViewContext.RouteData.Values["JobStatusID"] + "'}";

        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Maintenance", Action = "JobStatusInlineAddNewPartial" };
        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Maintenance", Action = "JobStatusInlineEditPartial" };
        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Maintenance", Action = "JobStatusInlineDeletePartial" }; 

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

        //Command column
        settings.CommandColumn.Visible = true;
        settings.CommandColumn.NewButton.Visible = true;
        settings.CommandColumn.DeleteButton.Visible = true;
        settings.CommandColumn.EditButton.Visible = true;
        settings.CommandColumn.Caption = "Actions";
        settings.CommandColumn.Width = 60; //Width is actually 100 not 60

        //for filtering
        settings.Settings.ShowFilterRow = true;
        settings.Settings.ShowFilterRowMenu = true;
        settings.CommandColumn.ClearFilterButton.Visible = true;

        settings.Columns.Add(column =>
        {
            column.FieldName = "JobStatusID";
            column.Caption = "JobStatusID";
            column.Visible = false;
        });

        settings.Columns.Add(column =>
        {
            column.FieldName = "SiteID";
            column.Caption = "SiteID";
            column.Visible = false;
        });

        settings.Columns.Add(column =>
        {
            column.FieldName = "JobStatusName";
            column.Caption = "Status Description";
            column.Settings.AllowAutoFilter = DefaultBoolean.True;
        });

        settings.Columns.Add(column =>
        {
            column.FieldName = "JobStatusCurrent";
            column.Caption = "Is Current";
            column.ColumnType = MVCxGridViewColumnType.CheckBox;
            column.Settings.AllowAutoFilter = DefaultBoolean.False;
        });

        settings.Columns.Add(column =>
        {
            column.FieldName = "JobStatusSortOrder";
            column.Caption = "Sort Order";
            column.Settings.AllowAutoFilter = DefaultBoolean.False;
        });
    });
}@grid.Bind(Model.JobStatus.ToList()).GetHtml()
4

2 回答 2

2

试试这个:

@{
Html.EnableClientValidation(true);

var grid = Html.DevExpress().GridView(
    settings =>
    {
        //your code
        //Add this code to initialize the rows for a New Row
        settings.InitNewRow = (sender, e) =>
        {
                e.NewValues["JobStatusSortOrder"] = 0; // set the default value as 0
        };
    });
}@grid.Bind(Model.JobStatus.ToList()).GetHtml()
于 2013-04-26T00:44:17.653 回答
0

由于它是数字类型,因此 DevExpress 网格中的任何空值都应等于数据结构中的 null。你不能只检查空字符串的编辑值,然后在发送到数据层之前将它们设置为 null 吗?

于 2013-01-14T17:55:14.673 回答