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

Set initial model value in dropdown list

Thread ID:





145049 Jun 4,2019 09:15 AM UTC Jun 7,2019 06:08 AM UTC ASP.NET Core - EJ 2 3
Tags: Dropdown List
Asked On June 4, 2019 09:15 AM UTC

Hi, I have created a dropdown list inside the editor template folder for an asp net core 2 project.
The dataSource comes from a viewbag collection.

This is the dropdown definition:

   <ejs-dropdownlist id="@ViewData.ModelExplorer.Metadata.PropertyName" allowFiltering="true" dataSource="@ViewData[collectionName]" value="@Model">
        <e-dropdownlist-fields text="Text" value="Value" />

This is the collection:


In Create mode everything is working. The list is filled and the correct value is returned.
When I go in Edit mode, the selected value is passed to the template, because @Model contains it, but the dropdown doesn't show the corresponding text.
If I confirm the view, the correct value is posted back to the controller. This means that the dropdown knows the current value, but it doesn't diplay the associated data.

The dropdown contains the elements, because the page code contains this at the bottom and I can see them if I open the dropdown:

var DropDownListqzmnpn3x1hp=new ejs.dropdowns.DropDownList({
  "allowFiltering": true,
  "dataSource": ejs.data.DataUtil.parse.isJson([....

For testing, if I set the index property it selects an item, but it's not the correct one, because index starts from 0 to collection.count - 1, while the value passed to the template is the value of the selected item (1, 10, 21 or 43).

So, how can I set and display the default value when the view is loaded?

Thanks, Marco

Karthik Ravichandran [Syncfusion]
Replied On June 5, 2019 11:52 AM UTC

Hi Macro, 

Thanks for contacting Syncfusion support. 

We have checked your query. We would like to inform you that reported issue may occurs due to mapping the value fields as a collection(Value= @Model). We have suggested you to set the value as any one particular data only like below. 

<ejs-dropdownlist id="@ViewData.ModelExplorer.Metadata.PropertyName" allowFiltering="true" dataSource="@ViewData[collectionName]" value="@Model.Value"> 
    <e-dropdownlist-fields text="Text" value="Value" /> 

Note: Based on your application model data, please change the field name in value API 
If we misunderstood your requirement, please share your requirement with more details this will help us to provide the solution at earliest. 

Karthik R 

Replied On June 6, 2019 02:59 PM UTC

Ciao Karthik,

your solution didn't solve my issue because the model is dynamic and there isn't a value property...The model that I receive in the editor template view is the real property, but after some digging, I've understood the problem.
It's due to type mismatch.
The source for the dropdownlist is a List<SelectListItem> where the key value is a STRING, while in my model the value is a INT.
I had to add value="@(Model.ToString()) and now it works perfectly.


Prince Oliver [Syncfusion]
Replied On June 7, 2019 06:08 AM UTC

Hello Marco, 

Thanks for your update. We are glad that the issue is resolved in your end. Please let us know if you need any further assistance. 



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