Domanda

I think I need to set some ConvertEmptyStringToNull property to false to get rid of the brain dead UpdateModel behavior that converts a field already set to an empty string to a null value which cause my database updates to fail, but I can't find this property anywhere in the DevExpress MVC Gridview. Anyone know how to find it?

I already tried to override the following in Application_Start

ModelBinders.Binders.DefaultBinder = new DevExpress.Web.Mvc.DevExpressEditorsBinder();

and setting

bindingContext.ModelMetadata.ConvertEmptyStringToNull = false;

there but that did not work.

Thanks for any ideas!

È stato utile?

Soluzione

The below works Ok for my purposes since I at least do not have to individually set every such property but strongly feel user data should NOT be changed by default. I made the suggestion to the DevExpress folks that there should be easier ways to override this behavior at field, grid and global levels. Here is my interim solution:

    settings.DataBound = (sender, e) =>
    {
        // turn off brain dead conversion of user data empty strings to null
        var lGrid = sender as MVCxGridView;
        foreach (var lCol in lGrid.Columns)
        {
            if (lCol is GridViewDataColumn)
            {
                GridViewDataColumn lDataCol = lCol as GridViewDataColumn;
                TextBoxProperties tb = lDataCol.PropertiesEdit as TextBoxProperties;
                if (tb != null)
                    tb.ConvertEmptyStringToNull = false;
            }
        }
    };
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top