We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Null Foreign Key Field Being Returned To Controller As 0 When Adding New Row In Batch Edit Mode

I have a foreign key field column that is returning a value of 0 to the controller for newly created rows. However, a null is correctly returned if I update existing rows. How can I get a null value to be returned for new rows?

Here is the column declaration:
col.Field("TransferToBrokerageSubAccountId").ForeignKeyField("BrokerageSubAccountId").ForeignKeyValue("FullAccountName").DataSource(((IEnumerable<object>)ViewBag.SubAccounts)).HeaderText("Transfer To").Add();

I am using the grid in batch edit mode with the datasource configured as:
.Datasource(ds => ds.URL(@Url.Action("BatchDataSource", "AccountTransaction")).BatchURL(@Url.Action("BatchUpdate", "AccountTransaction")).Adaptor(AdaptorType.UrlAdaptor))

And the class that it is being put into is (with most fields omitted):

// class does not have any defined constructors
public class BrokerageAccountTransactionRow
    #region Properties and Indexers

    public decimal Amount { get; set; }
    public int BrokerageSubAccountId { get; set; }
    public int? TransferToBrokerageSubAccountId { get; set; }

Regards, Jeff

1 Reply

GV Gowthami V Syncfusion Team January 7, 2016 09:28 AM UTC

Hi Jeff,

Thanks for using Syncfusion products.

We have analyzed your issue and we found that by default, for number type columns the default value is 0. So that only while adding new rows the value passed as 0.

We can resolve the issue by set “DefaultValue” property of the columns as empty string for the corresponding foreign key column as follows,

            .Datasource(ds => { ds.URL(Url.Action("BatchDataSource")).BatchURL(Url.Action("DetailUpdate")).Adaptor(AdaptorType.UrlAdaptor); })
. . . .
. . . .

.Columns(col =>

col.Field("EmployeeID").HeaderText("Employee Name").DefaultValue("").ForeignKeyField("EmployeeID")

. . . .

For your reference we have attached the sample (version below,


Refer to the below screenshot,

If we misunderstood your issue , share us the sample with the issue which will help to analyze the issue and provide you the response as early as possible.


Gowthami V.

Live Chat Icon For mobile
Up arrow icon