- Home
- Forum
- ASP.NET Core
- Assign Value to DropDown
Assign Value to DropDown
Hi Syncfusion support
Attachment: syncfusion_support_f67f774c.rar
I have the issues regarding the dropdown. My problem is
a. when i'm using this belows code
<ej-drop-down-list id="GenderList" datasource="ViewBag.datasourceGender" value="10">
<e-drop-down-list-fields text="GenderName" value="GenderId" />
</ej-drop-down-list>
i able to set dropdown based on the value (image a)
but
when i'm using this code whisch viewbag.genderid has been set in controller, nothing happen (image b)
<ej-drop-down-list id="GenderList" datasource="ViewBag.datasourceGender" value="viewbag.genderid">
<e-drop-down-list-fields text="GenderName" value="GenderId" />
</ej-drop-down-list>
can you advice on this matters, thanks for the support
Attachment: syncfusion_support_f67f774c.rar
SIGN IN To post a reply.
2 Replies
HA
haryzad
September 11, 2017 02:58 PM UTC
Hi Syncfusion support,
Thanks for the help, currently i'm using the alternative by pass the value through the model as below and can be used for now
<ej-drop-down-list id="GenderList" datasource="ViewBag.datasourceGender" value= "@Model.GenderId">
<e-drop-down-list-fields text="GenderName" value="GenderId" />
</ej-drop-down-list>
KR
Keerthana Rajendran
Syncfusion Team
September 12, 2017 12:37 PM UTC
Hi Haryzad,
Thank you for contacting Syncfusion support.
Yes, you can set the selected value through model by using Value property as mentioned in your update. You can also pass it through ViewBag using value property as shown in the below code
|
<ej-drop-down-list id="GenderList" datasource="(IEnumerable<WebApplication1.Controllers.SelectListItem>)ViewBag.dataSourceGender" [email protected]>
<e-drop-down-list-fields text="GenderName" value="GenderId" />
</ej-drop-down-list> |
|
public IActionResult Index()
{
GenderList.Add(new SelectListItem { GenderId = 0 , GenderName ="Male"});
GenderList.Add(new SelectListItem { GenderId = 1, GenderName = "Female" });
ViewBag.dataSourceGender = GenderList;
ViewBag.Value = 1;
return View();
} |
We have attached a sample for reference. Please download the sample from
Regards,
Keerthana
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
HA haryzad
- Sep 11, 2017 02:36 PM UTC
- Sep 12, 2017 12:37 PM UTC