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

Multi tool use
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");
– Stephen Muecke
Jul 3 at 8:40


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.

1oQrABj
Fe2B,zo lR,4uqQ6K5NEJq0Hem5RKUjAiv6S

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications