How to get dataTextField instead of dataValueField in Dropdownlist in asp.net mvc?

Multi tool use
How to get dataTextField instead of dataValueField in Dropdownlist in asp.net mvc?
I've sent the viewbag for a cardtype dropdown in a form as follows :
var CardType = CommonService.GetCardType();
ViewBag.CardType = new SelectList(CardType, "Id", "CardType");
Now I'm trying to save it in the database as follows :
IdCardType = model.IDCardType;
This code saves the dataValueField (i.e. "Id"), but I need to save the dataTextField (i.e. "CardType") and I don't know how to do that.
Can anyone help me out here ?
Thanks
ViewBag.CardType = new SelectList(CardType, "CardType", "CardType");
Thanks for writing @StephenMuecke ! But isn't there any way to edit this code "IdCardType = model.IDCardType;" and get the desired result ?
– Shiwa
Jul 3 at 8:46
That will give you the result - it binds to the value of
CardType
not Id
!– Stephen Muecke
Jul 3 at 8:53
CardType
Id
please refer this link stackoverflow.com/questions/47284093/…
– Praveen Rao Chavan.G
Jul 3 at 9:10
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
ViewBag.CardType = new SelectList(CardType, "CardType", "CardType");
– Stephen Muecke
Jul 3 at 8:40