Rendering ejs-dropdownlist from a tag-helper not rendering selected option

I've created a tag helper that helps some pre-processing before generating the ejs-dropdownlist. It is able to render the control, and post the data, but I can't seem to bind the selected data on load. Upon checking the generated HTML, the selected properties in the json are all set to false.

// Helper Tag
<editor-list asp-for="CityId" list-items="Model.AvailableCities"/>

is redered to


// EditorTemplate
<ejs-dropdownlist id="@Html.IdForModel()"
                  dataSource="@((IEnumerable<SelectListItem>)ViewData["SelectList"])"
                  placeholder="@((string)ViewData["ResourceName"])"
                  floatLabelType="Always"    
                  readonly="@((bool)ViewData["ControlDisabled"])"

                  // what i've tried
                  value="@Model"               
                  ejs-for="@Html.IdForModel()"
                  ejs-for="@Model"
                    >

    <e-dropdownlist-fields value="Value" text="Text"></e-dropdownlist-fields>
</ejs-dropdownlist>

3 Replies 1 reply marked as answer

BC Berly Christopher Syncfusion Team January 29, 2021 11:37 AM UTC

Hi Andrew, 
  
Greetings from Syncfusion support. 
  
We would like to inform you that while using the ejs-for the DropDownList component, we need to assign the data source on POST action. Since, the component will be re-rendered, and data source gone as null. This will lead to render the DropDownList component without data and selected value.  
  
So, we suggest you to assign the data source on POST action to resolve the reported issue in your end. 
  
  
  
  
Still issue persists, please share the code of POST action that will help us to check and proceed further at our end. 
  
Regards, 
Berly B.C 


Marked as answer

AN Andrew February 5, 2021 08:08 AM UTC

Hi Berly,

Thanks for answering!

I'm actually having trouble with loading the page. The selected value is not "selected" in the control. I digged through the <ejs-scripts> that is rendered and saw that the selected item is actually flagged as True. I don't get why it doesn't reflect on the control

new ejs.dropdowns.DropDownList({dataSource:ejs.data.DataUtil.parse.isJson([
{Disabled:!1,Group:null,Selected:!1,Text:"dsad",Value:"b0868b73-0511-4d6e-bc99-fb02bd1caf32"},{Disabled:!1,Group:null,Selected:!0,Text:"Product Cat",Value:"a9b48a80-17ee-472e-bb54-7a6134b572de"}
]),fields:{text:"Text",value:"Value"},floatLabelType:"Always",ignoreAccent:!1,placeholder:"Associated Category Type",zIndex:1e3}).appendTo("#AssociatedCategoryTypeId");





BC Berly Christopher Syncfusion Team February 8, 2021 12:02 PM UTC

Hi Andrew, 
  
As we mentioned earlier, after form POST action component will be re-rendered and data source will be null. If the pre-select value available in the value property, this will not assign to the component since data source is empty. This may be the cause of the reported issue. So, please share the code snippet of data source assigned to the component in the POST action that will help us to check and proceed further at our end. 
  
Regards, 
Berly B.C 


Loader.
Up arrow icon