BoldSign®Effortlessly integrate e-signatures into your app with the BoldSign® API. Create a sandbox account!
public IActionResult Index()
{
ViewBag.Data = new Vegetables().VegetablesList();
ViewBag.Value = "Onion";
return View();
}
<ejs-dropdownlist id="dropdown" name="Value" dataSource="ViewBag.data" value="ViewBag.Value" placeholder="Select a country">
<e-dropdownlist-fields value="Vegetable"></e-dropdownlist-fields>
</ejs-dropdownlist>
|
|
Hello There,
I'm having an issue while trying to preselect a value in a custom edit page.
My viewbag looks like this:
ViewBag.Depozit = await _context.tWDepozites.Where(x => x.aWDepoID == document.iWDocDepozit).Select(x => new { ID = x.aWDepoID, Text = x.sWDepoName }).ToListAsync();
My dropdownlist code:
<ejs-dropdownlist id="iWDocDepozit" dataSource="@ViewBag.Depozit" placeholder="Depozit" floatLabelType="Always" popupHeight="300px" ejs-for="iWDocDepozit" required>
<e-dropdownlist-fields text="Text" value="ID"></e-dropdownlist-fields>
</ejs-dropdownlist>
The viewbag only contains one item and the datasource works properly.
How can i preselect that item?
Thank you!
Hi Ssekamatte James,
Thank you for reaching out with your query about preselecting a value in a custom edit page.
We've examined your requirements and have prepared a sample code snippet that should address your needs:
<ejs-dropdownlist id="dropdown" name="Value" dataSource="ViewBag.Data" floatLabelType="Always" popupHeight="300px" ejs-for="@Model.Values" placeholder="Select a country"> <e-dropdownlist-fields text="Vegetable" value="Id"></e-dropdownlist-fields> </ejs-dropdownlist>
[HomeController.cs]
public IActionResult Index() { DropdownListValue model = new DropdownListValue(); ViewBag.Data = new DropdownListValue().VegetablesList(); model.Values = "item1"; return View(model); } |
In the provided code snippet, we've utilized a model to bind the preselected value. Please integrate these changes into your code and verify if they meet your requirements.
If you encounter any further issues or need additional assistance, please feel free to reach out.
Regards,
Kokila Poovendran.