Default Value for Dropdown

How to set default value for ejs-dropdownlist using .net core razor pages.Please find attached sample code



Attachment: Dropdownlist_e3cf49f0.7z

1 Reply

VJ Vinitha Jeyakumar Syncfusion Team September 20, 2021 11:11 AM UTC

Hi Nitin, 
 
 
Greetings from Syncfusion support 
 
 
We have validated your query “Default Value for Dropdown 
 
Your requirement to set the default value for the DropDown list can be achieved by using the Index or Value property of DropDown list. Please check the below code, 
 
Code snippet: 
Index.cshtml 
<div> 
        <ejs-dropdownlist id="games" value="@ViewBag.Value" dataSource="@ViewBag.data" placeholder="Select a game" popupHeight="220px"> 
        </ejs-dropdownlist> 
    </div> 
    <div> 
        <ejs-dropdownlist id="games1" index="1" dataSource="@ViewBag.data" placeholder="games" popupHeight="220px"> 
        </ejs-dropdownlist> 
    </div> 
 
HomeController.cs 
public ActionResult Index() 
        { 
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" }; 
            ViewBag.Value = "Cricket"; 
            return View(); 
        } 
 
 
 
Please check the above sample and code snippet and let us know if it satisfies your requirement. 
 
Regards, 
Vinitha 


Loader.
Up arrow icon