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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

ASP.NET Core Razor pages - Multiselect Dropdown values are NULL (OnPost eve)

Thread ID:

Created:

Updated:

Platform:

Replies:

145942 Jul 15,2019 12:24 PM UTC Jul 19,2019 10:27 AM UTC ASP.NET Core - EJ 2 3
loading
Tags: MultiSelect Dropdown
Flavio
Asked On July 15, 2019 12:24 PM UTC

Hello,
I've been trying to use complex objects to bind to my multiselect dropdown component, but I'm struggling to see the values and bind the values OnPost event of my razor page (NOT MVC).

Some notes:
1) If I use simply array o string (string []), I can see all the values, bind them, and I click selecting multiple values, I can see that the values are selected.
2) If I use complex object, for example, the multiselect dropdown will be populated by a List<MyObject>, where I'm trying to do the following:
     1.1)MyObject has several properties, and I'm using for the text and value property the same value, for example, MyObject has on property called string Feeling_Desc, where Desc will the value AND the text to be shown in the dropdown list. In this case, the drowdown populates correctly with the Desc values there (Desc1, Desc2, etc,). However after selecting the values when I click elsewhere in the page, change the focus to any other place in the page, the dropdown does not "indicates" the values are selected, even though if click on it again, it shows me the values I've selected.
   2.2) On clicking on my button to submit the form, the OnPost event shows NULL for the List<MyObject> that was bound to the component in the OnGet event. My property has [Bindproperty] on it so I'm lost as what is going on.

<div class="col-sm-4">
                                        <ejs-multiselect id="gutfeelingentrada" dataSource="@Model.gutFeelingsEntradaBind" ejs actionBegin="onBegin" dataBound="onBound" ejs-for="@Model.gutFeelingsEntradaBind"  placeholder="Test" mode="Default">
                                            <e-multiselect-fields value="MyObject.Feeling_Desc" text="MyObject.Feeling_Desc"></e-multiselect-fields>
                                        </ejs-multiselect>
                                    </div>
<script>
                                        var selected = [];
                                        function onBegin(e) {
                                            this.fields = {
                                                text: 'Feeling_Desc', value: 'Feeling_Desc', itemCreated: function (e) {
                                                    var count = 0;
                                                    if (count === 0) {
                                                        for (let i = 0; i < e.dataSource.length; i++) {
                                                            if (e.curData.isSelected == true)
                                                                itemSearch(e.curData.Code); //pass the corresponding value
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        function itemSearch(e) {
                                            if (selected.indexOf(e) == -1)
                                                selected.push(e);
                                        }
                                        function onBound(e) {
                                            this.value = selected;
                                        }
                                    </script>
public class MyObject
    {
        public int TradingJournalFeelings_Num { get; set; }
        public int? TradingJournalNum { get; set; }
        public string FeelingType { get; set; }
        public string Feeling_Desc { get; set; }
        public bool isSelected { get; set; }
    }

[BindProperty]
        public List<MyObject>gutFeelingsEntradaBind { get; set; }

Could you please kindly help me?

Thanks,
Flavio

Prince Oliver [Syncfusion]
Replied On July 18, 2019 06:09 AM UTC

Hi Flavio, 

Thank you for your update. 

Query 1: However after selecting the values when I click elsewhere in the page, change the focus to any other place in the page, the dropdown does not "indicates" the values are selected, even though if click on it again, it shows me the values I've selected 

We have checked this reported scenario in our end. Unfortunately, we were unable to replicate the issue in our end. Kindly share us more details on this issue with screenshots or video demonstration. If possible please replicate the issue in the below sample and revert us. 

Query 2: On clicking on my button to submit the form, the OnPost event shows NULL for the List<MyObject> that was bound to the component in the OnGet event. My property has [Bindproperty] on it so I'm lost as what is going on. 

We were able to get the bounded model value in the OnPost method. Please refer to the screenshot below, 

 

We have attached the sample for your reference, please find it in the following location 

Regards, 
Prince 


Flavio
Replied On July 18, 2019 10:43 AM UTC

Hello Prince,
Thank you for your response.

However, the example that you posted here when posting you're selecting only one value from the collection (Icons). I would like to have access to the collection of all items selected by the user when posting, not only one. If the user selects three items, when posting I want to have access to all of the 3 items to be able to iterate through them and do the needful according to my business rules.

Could you please kindly help me achieve that using the example that you posted here?


Cheers,
Flavio

Prince Oliver [Syncfusion]
Replied On July 19, 2019 10:27 AM UTC

Hi Flavio, 

Thank you for your update. 

To access all the selectedItems in the server-side, you need to define the model variable as string[] array instead of string. Kindly refer to the following code. 

[HttpPost] 
public void OnPost(Country SelectedIcon) 
{ 
           
    // Access the selected value here 
    string[] selected = SelectedIcon.CountryId; 
             
} 
// define as array here 
public class Country 
{ 
    public string[] CountryId { get; set; } 
} 

Let us know if you need any further assistance on this. 

Regards, 
Prince 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon