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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

121606 Jan 6,2016 07:25 PM Jan 7,2016 04:28 AM ASP.NET MVC 1
loading
Tags: Grid
Jeffrey Stone
Asked On January 6, 2016 07:25 PM

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; }
   
    #endregion
}


Regards, Jeff



Gowthami V [Syncfusion]
Replied On January 7, 2016 04:28 AM

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,

@(Html.EJ().Grid<MvcApplication14.OrdersView>("FlatGrid")
            .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")

               .ForeignKeyValue("FirstName").DataSource((IEnumerable<object>)ViewBag.dataSource2)
               .TextAlign(TextAlign.Left).Width(90).Add();
. . . .
   }))



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

http://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample1141007308.zip

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.

Regards,

Gowthami V.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;