Does anyone knows how to generate IEnumerable and set the Text property in controller/Edit CudtomerName and CustomerSurname as shown below?
In Payment/Create controller I replace;
ViewBag.PaymentCustomer = new SelectList(db.CUSTOMERS, "CUSTID", "CustomerName");
with this:
ViewBag.PaymentCustomer = db.CUSTOMERS.ToList().Select(c => new SelectListItem
{
Value = c.CUSTID.ToString(),
Text = string.Format("{0} {1}", c.CustomerName, c.CustomerSurname)
});
and its working. But in Payment/Edit is:
ViewBag.PaymentCustomer = new SelectList(db.CUSTOMERS, "CUSTID", "CustomerName", pAYMENT.PaymentCustomer);
Both ViewBag.PaymentCustomer looks same. The Payment/Edit its also get 4th parameter as "pAYMENT.PaymentCustomer". I cannot use "pAYMENT.PaymentCustomer" in db.CUSTOMERS.ToList().Select...
I try this:
//ViewBag.PaymentCustomer = new SelectList(db.CUSTOMERS, "CUSTID", "CustomerName", pAYMENT.PaymentCustomer); ViewBag.PaymentCustomer = new SelectList(db.CUSTOMERS.ToList().Select(c => new SelectListItem { Value = c.CUSTID.ToString(), Text = string.Format("{0} {1}", c.CustomerName, c.CustomerSurname) }), pAYMENT.PaymentCustomer);
And After build and run. I can see dropdown list and inside drop down list does not shows Customername and CustomerSurname. It shows "System.Web.Mvc.SelectListItem".
How do I do that?